Cryptic-looking functions (iif, eq, neq etc) removed
This commit is contained in:
@@ -62,4 +62,6 @@ public fun <T, C: Collection<T>> C.ifEmpty(body: () -> C): C = if (isEmpty()) bo
|
||||
|
||||
public fun <T> Iterable<Iterable<T>>.flatten(): List<T> {
|
||||
return flatMapTo(ArrayList<T>(), {it})
|
||||
}
|
||||
}
|
||||
|
||||
public fun <T: Any> emptyOrSingletonList(item: T?): List<T> = if (item == null) listOf() else listOf(item)
|
||||
@@ -16,20 +16,9 @@
|
||||
|
||||
package org.jetbrains.kotlin.util
|
||||
|
||||
fun Boolean.iif<T>(then: T, _else: T): T = if (this) then else _else
|
||||
|
||||
fun <T: Any, R> T?.inn(then: (T) -> R, _else: R): R = if (this != null) then(this) else _else
|
||||
|
||||
// These two functions are needed in conjunction with iif:
|
||||
// foo.eq(bar).iif(a, b)
|
||||
fun <T> T.eq(eq: T): Boolean = this == eq
|
||||
fun <T> T.neq(eq: T): Boolean = this != eq
|
||||
|
||||
fun <T: Any> T?.sure(message: String): T {
|
||||
if (this == null)
|
||||
throw AssertionError(message)
|
||||
return this
|
||||
}
|
||||
fun <T: Any> T?.sure(message: String): T = this ?: throw AssertionError(message)
|
||||
|
||||
fun <T> T.printAndReturn(message: String = ""): T {
|
||||
if (!message.isEmpty()) {
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
package org.jetbrains.jet.utils
|
||||
|
||||
import java.util.Collections
|
||||
|
||||
public fun <T> emptyList(): MutableList<T> = Collections.emptyList<T>() as MutableList
|
||||
public fun <T: Any> emptyOrSingletonList(item: T?): MutableList<T> = if (item == null) emptyList() else Collections.singletonList(item) as MutableList
|
||||
|
||||
public fun <T> emptySet(): MutableSet<T> = Collections.emptySet<T>() as MutableSet
|
||||
public fun <K, V> emptyMap(): MutableMap<K, V> = Collections.emptyMap<K, V>() as MutableMap
|
||||
|
||||
Reference in New Issue
Block a user