doc /


Contains utility functions for APIs.



class ArgumentMapperBuilder<out T>

Builder to map variable length arguments formulated as (first: T, vararg others : T) to something else.


class ArgumentToNullOrMapperBuilder<T : Any>

Builder to map variable length arguments formulated as (first: T, vararg others : T) to something else.


interface Group<out T>

Represents a group of T.


interface GroupWithNullableEntries<out T> : Group<T>

Represents a group of T (where T: Any?) which can be converted to a List<T>


interface GroupWithoutNullableEntries<out T> : Group<T>

Represents a group of T (where T: Any) which can be converted to a List<T>


interface VarArgHelper<out T>

Represents a parameter object used to express the arguments T, vararg T and provides utility functions to transform them.



fun <T> groupsToList(firstGroup: Group<T>, secondGroup: Group<T>, otherGroups: Array<out Group<T>>): List<List<T>>

Adds the given firstGroup, the secondGroup and the otherGroups into a new List and returns it.


fun <T> iterableLikeToIterable(iterableLike: IterableLike): Iterable<T>


fun <T> iterableToPair(iterable: Iterable<T>): Pair<T, Array<out T>>


fun <T> mapArguments(first: T, others: Array<out T>): ArgumentMapperBuilder<T>
fun mapArguments(first: Byte, others: ByteArray): ArgumentMapperBuilder<Byte>
fun mapArguments(first: Char, others: CharArray): ArgumentMapperBuilder<Char>
fun mapArguments(first: Short, others: ShortArray): ArgumentMapperBuilder<Short>
fun mapArguments(first: Int, others: IntArray): ArgumentMapperBuilder<Int>
fun mapArguments(first: Long, others: LongArray): ArgumentMapperBuilder<Long>
fun mapArguments(first: Float, others: FloatArray): ArgumentMapperBuilder<Float>
fun mapArguments(first: Double, others: DoubleArray): ArgumentMapperBuilder<Double>
fun mapArguments(first: Boolean, others: BooleanArray): ArgumentMapperBuilder<Boolean>

Creates a ArgumentMapperBuilder with the given first and others as arguments; specify the mapping as such using a subsequent step in the building process.

fun <T, R> mapArguments(first: T, others: Array<out T>, mapper: (T) -> R): Pair<R, Array<out R>>
fun <R> mapArguments(first: Byte, others: ByteArray, mapper: (Byte) -> R): Pair<R, Array<out R>>
fun <R> mapArguments(first: Char, others: CharArray, mapper: (Char) -> R): Pair<R, Array<out R>>
fun <R> mapArguments(first: Short, others: ShortArray, mapper: (Short) -> R): Pair<R, Array<out R>>
fun <R> mapArguments(first: Int, others: IntArray, mapper: (Int) -> R): Pair<R, Array<out R>>
fun <R> mapArguments(first: Long, others: LongArray, mapper: (Long) -> R): Pair<R, Array<out R>>
fun <R> mapArguments(first: Float, others: FloatArray, mapper: (Float) -> R): Pair<R, Array<out R>>
fun <R> mapArguments(first: Double, others: DoubleArray, mapper: (Double) -> R): Pair<R, Array<out R>>
fun <R> mapArguments(first: Boolean, others: BooleanArray, mapper: (Boolean) -> R): Pair<R, Array<out R>>

Maps the given first and others to the given type R with the help of the given mapper.


fun <T> nullable(t: T): T?

Turns the given type into a nullable type.

fun <T> nullable(t: KFunction0<T>): KFunction0<T?>
fun <T1, R> nullable(t: KFunction1<T1, R>): KFunction1<T1, R?>
fun <T1, T2, R> nullable(t: KFunction2<T1, T2, R>): KFunction2<T1, T2, R?>
fun <T1, T2, T3, R> nullable(t: KFunction3<T1, T2, T3, R>): KFunction3<T1, T2, T3, R?>
fun <T1, T2, T3, T4, R> nullable(t: KFunction4<T1, T2, T3, T4, R>): KFunction4<T1, T2, T3, T4, R?>
fun <T1, T2, T3, T4, T5, R> nullable(t: KFunction5<T1, T2, T3, T4, T5, R>): KFunction5<T1, T2, T3, T4, T5, R?>

Turns the given function reference into a function reference with a nullable return type.


fun <T> nullableContainer(iterable: Iterable<T>): Iterable<T?>

Turns an Iterable into an iterable with a nullable element type.

fun <T> nullableContainer(arr: Array<out T>): Array<out T?>

Turns an Array into an array with a nullable element type.


fun <K, V : Any> nullableKeyMap(map: Map<out K, V>): Map<out K?, V>

Turns a Map into a map with a nullable key type.


fun <K, V> nullableKeyValueMap(map: Map<out K, V>): Map<out K?, V?>

Turns a Map into a map with a nullable key and a nullable value type.


fun <K : Any, V> nullableValueMap(map: Map<K, V>): Map<K, V?>

Turns a Map into a map with a nullable value type.


fun <T : Any> subAssert(assertionCreator: Assert<T>.() -> Unit): Assert<T>.() -> Unit

Helper function to create an Assert&lt;T&gt; lambda with receiver; helps to circumvent Kotlin type inference bugs involving lambdas.


fun <T> subAssertNullable(assertionCreator: AssertionPlantNullable<T>.() -> Unit): AssertionPlantNullable<T>.() -> Unit

Helper function to create an AssertionPlantNullable lambda with receiver; helps to circumvent Kotlin type inference bugs involving lambdas.


fun <T> subExpect(assertionCreator: Expect<T>.() -> Unit): Expect<T>.() -> Unit


fun <T : Any> ArgumentMapperBuilder<T?>.toNullOr(): ArgumentToNullOrMapperBuilder<T>

Maps each argument to null if it is already null and if not, then ...


fun <T> toVarArg(iterableLike: IterableLike): Pair<T, Array<out T>>

Transforms the given IterableLike to Pair<T, Array<out T>> with the intend that it can be easily used for a function requiring T, vararg T


fun validateAtMost(times: Int, atMostCall: (Int) -> String, atLeastCall: (Int) -> String, exactlyCall: (Int) -> String): Unit

Validates that times is not 1; throws an IllegalArgumentException otherwise, pointing the user to use the given exactlyCall instead of the given atMostCall.


fun validateButAtMost(atLeastTimes: Int, butAtMostTimes: Int, atLeastButAtMostCall: (Int, Int) -> String, atLeastCall: (Int) -> String, butAtMostCall: (Int) -> String, exactlyCall: (Int) -> String): Unit

Validates that atLeastTimes is not equal to or greater than butAtMostTimes; throws IllegalArgumentException otherwise, pointing the user to use the given exactlyCall in case atLeastTimes equals butAtMostTimes.