<commit_before>package com.commonsense.android.kotlin.base.extensions.collections

import com.commonsense.android.kotlin.base.EmptyFunction
import com.commonsense.android.kotlin.base.FunctionUnit
import com.commonsense.android.kotlin.base.extensions.isNull

/**
 * Created by <NAME> on 06-12-2016.
 */

/**
 * performs the action if the boolean is true.
 */
inline fun Boolean.onTrue(crossinline action: EmptyFunction): Boolean {
    if (this) {
        action()
    }
    return this
}


/**
 * Maps a boolean into a value.
 */
fun <T> Boolean.map(ifTrue: T, ifFalse: T): T = if (this) {
    ifTrue
} else {
    ifFalse
}


/**
 * performs the given action if we are null
 */
inline fun Any?.ifNull(crossinline action: EmptyFunction) {
    this.isNull.ifTrue(action)
}

/**
 * performs the given action, if we are not null
 */
inline fun <T> T?.ifNotNull(crossinline action: FunctionUnit<T>) {
    this?.let { action(it) }
}

/**
 * Makes a more "elegant" sentence for some expressions, same as "com.commonsense.android.kotlin.base.extensions.collections.onTrue"
 */
inline fun Boolean.ifTrue(crossinline action: EmptyFunction): Boolean = onTrue(action)

/**
 * performs the action if the boolean is false.
 */
inline fun Boolean.onFalse(crossinline action: EmptyFunction): Boolean {
    if (!this) {
        action()
    }
    return this
}


/**
 * Makes a more "elegant" sentence for some expressions, same as "com.commonsense.android.kotlin.base.extensions.collections.onTrue"
 */
inline fun Boolean.ifFalse(crossinline action: EmptyFunction): Boolean = onFalse(action)

inline fun <reified T : kotlin.Enum<T>> valueOfOrUnsafe(type: String?, orValue: T?): T? =
        java.lang.Enum.valueOf(T::class.java, type) ?: orValue

inline fun <reified T : kotlin.Enum<T>> enumFromOr(type: String?, orValue: T): T =
        java.lang.Enum.valueOf(T::class.java, type) ?: orValue

inline fun <reified T : kotlin.Enum<T>> enumFromOrNull(type: String?): T? =
        java.lang.Enum.valueOf(T::class.java, type) ?: null


val IntRange.length
    get() = (last - start) + 1 //+1 since start is inclusive.

val IntRange.largest
    get() = maxOf(last, start)<commit_msg>use kotlin to find the enum value rather than java, so no exceptions ect.<commit_after>package com.commonsense.android.kotlin.base.extensions.collections

import com.commonsense.android.kotlin.base.EmptyFunction
import com.commonsense.android.kotlin.base.FunctionUnit
import com.commonsense.android.kotlin.base.extensions.isNull

/**
 * Created by <NAME> on 06-12-2016.
 */

/**
 * performs the action if the boolean is true.
 */
inline fun Boolean.onTrue(crossinline action: EmptyFunction): Boolean {
    if (this) {
        action()
    }
    return this
}


/**
 * Maps a boolean into a value.
 */
fun <T> Boolean.map(ifTrue: T, ifFalse: T): T = if (this) {
    ifTrue
} else {
    ifFalse
}


/**
 * performs the given action if we are null
 */
inline fun Any?.ifNull(crossinline action: EmptyFunction) {
    this.isNull.ifTrue(action)
}

/**
 * performs the given action, if we are not null
 */
inline fun <T> T?.ifNotNull(crossinline action: FunctionUnit<T>) {
    this?.let { action(it) }
}

/**
 * Makes a more "elegant" sentence for some expressions, same as "com.commonsense.android.kotlin.base.extensions.collections.onTrue"
 */
inline fun Boolean.ifTrue(crossinline action: EmptyFunction): Boolean = onTrue(action)

/**
 * performs the action if the boolean is false.
 */
inline fun Boolean.onFalse(crossinline action: EmptyFunction): Boolean {
    if (!this) {
        action()
    }
    return this
}


/**
 * Makes a more "elegant" sentence for some expressions, same as "com.commonsense.android.kotlin.base.extensions.collections.onTrue"
 */
inline fun Boolean.ifFalse(crossinline action: EmptyFunction): Boolean = onFalse(action)

inline fun <reified T : kotlin.Enum<T>> enumFromOrNull(name: String?): T? {
    return enumValues<T>().find { it.name == name }
}

inline fun <reified T : kotlin.Enum<T>> enumFromOr(name: String?, orElse: T): T {
    return enumFromOrNull<T>(name) ?: orElse
}

val IntRange.length
    get() = (last - start) + 1 //+1 since start is inclusive.

val IntRange.largest
    get() = maxOf(last, start)
{'fraction_non_alphanumeric': 0.1301141769743102, 'fraction_numerical': 0.004757373929590866, 'mean_word_length': 3.7300337457817774, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1096137', 'n_tokens_mistral': 1387, 'n_tokens_neox': 1331, 'n_words': 378}