Package com.skydoves.whatif

Functions

Link copied to clipboard
inline fun <T : MutableCollection<E>, E> T.addAllWhatIfNotNull(element: Collection<E>?, whatIf: (T) -> Unit): T
inline fun <T : MutableCollection<E>, E> T.addAllWhatIfNotNull(element: Collection<E>?, whatIf: (T) -> Unit, whatIfNot: (T) -> Unit): T

An expression for adding an element and invoking whatIf when the element is not null.

Link copied to clipboard
inline fun <T : MutableCollection<E>, E> T.addWhatIfNotNull(element: E?, whatIf: (T) -> Unit): T
inline fun <T : MutableCollection<E>, E> T.addWhatIfNotNull(element: E?, whatIf: (T) -> Unit, whatIfNot: (T) -> Unit): T

An expression for adding an element and invoking whatIf when the element is not null.

Link copied to clipboard
inline fun <T : MutableCollection<E>, E> T.removeAllWhatIfNotNull(element: Collection<E>?, whatIf: (T) -> Unit): T

An expression for removing a collection of element and invoking whatIf when the element is not null.

inline fun <T : MutableCollection<E>, E> T.removeAllWhatIfNotNull(element: Collection<E>?, whatIf: (T) -> Unit, whatIfNot: (T) -> Unit): T

An expression for removing an element and invoking whatIf when the element is not null.

Link copied to clipboard
inline fun <T : MutableCollection<E>, E> T.removeWhatIfNotNull(element: E?, whatIf: (T) -> Unit): T
inline fun <T : MutableCollection<E>, E> T.removeWhatIfNotNull(element: E?, whatIf: (T) -> Unit, whatIfNot: (T) -> Unit): T

An expression for removing an element and invoking whatIf when the element is not null.

Link copied to clipboard
inline fun Boolean?.whatIf(whatIf: () -> Unit): Boolean?

An expression for invoking whatIf when the target Boolean is not null and true.

inline fun <T> T.whatIf(given: Boolean?, whatIf: T.() -> Unit): T

An expression for invoking whatIf when the given boolean is true. So it is useful when using with a chaining function like builder pattern or apply expression in kotlin.

inline fun <T> T.whatIf(given: () -> Boolean?, whatIfDo: T.() -> Unit): T

An expression for invoking whatIf when the given lambda's return value is true. So it is useful when using with a chaining function like builder pattern or apply expression in kotlin.

inline fun <T> T.whatIf(given: (T) -> Boolean?, whatIf: () -> Unit): T

An expression for invoking whatIf when the given boolean is true.

inline fun Boolean?.whatIf(whatIf: () -> Unit, whatIfNot: () -> Unit): Boolean?

An expression for invoking whatIf when the target object is not null and true. If the target is null or false, whatIfNot will be invoked instead of the whatIf.\

inline fun <T> T.whatIf(given: Boolean?, whatIf: T.() -> Unit, whatIfNot: T.() -> Unit): T

An expression for invoking whatIf when the given boolean is true. If the given boolean is false, whatIfNot will be invoked instead of the whatIf. So it is useful when using with a chaining function like builder pattern or apply expression in kotlin.

inline fun <T> T.whatIf(given: () -> Boolean?, whatIfDo: T.() -> Unit, whatIfNot: T.() -> Unit): T

An expression for invoking whatIf when the given lambda's return value is true. If the given boolean is false, whatIfNot will be invoked instead of the whatIfDo. So it is useful when using with a chaining function like builder pattern or apply expression in kotlin.

inline fun <T> T.whatIf(given: (T) -> Boolean?, whatIf: () -> Unit, whatIfNot: () -> Unit): T

An expression for invoking whatIf when the given boolean is true. If the given boolean is false, whatIfNot will be invoked instead of the whatIf.

Link copied to clipboard
inline fun Iterable<Boolean?>.whatIfAnd(whatIf: () -> Unit): Iterable<Boolean?>
inline fun Iterable<Boolean?>.whatIfAnd(whatIf: () -> Unit, whatIfNot: () -> Unit): Iterable<Boolean?>

An expression for operating And operator to a list of the nullable-Boolean.

inline fun Boolean?.whatIfAnd(predicate: Boolean?, whatIf: () -> Unit): Boolean?

An expression for invoking whatIf when the target Boolean is true and the predicate is also true.

Link copied to clipboard
inline fun Boolean?.whatIfElse(whatIf: () -> Unit): Boolean?

An expression for invoking whatIf when the target object is not null and false.

Link copied to clipboard
inline fun <T, R> T.whatIfLet(given: Boolean?, default: R, whatIf: (T) -> R): R

An expression for invoking whatIf when the given boolean value. If the given boolean value is false, the result value is the default. It is useful when the receiver T and the result R should be different.

inline fun <T, R> T.whatIfLet(given: Boolean?, whatIf: (T) -> R, whatIfNot: (T) -> R): R

An expression for invoking whatIf when the given boolean value. If the given boolean is false, whatIfNot will be invoked instead of the whatIf. It is useful when the receiver T and the result R should be different.

Link copied to clipboard
inline fun <T, R> T.whatIfMap(default: R, whatIf: (T) -> R): R
inline fun <T, R> T.whatIfMap(whatIf: (T) -> R, whatIfNot: (T) -> R): R

An expression for invoking whatIf when the T target object is not null. It is useful when the receiver T and the result R should be different.

inline fun <T, R> T.whatIfMap(given: Boolean?, default: R, whatIf: (T) -> R): R

An expression for invoking whatIf when the given boolean value. If the given boolean value is false, the result value is the default. It is useful when the receiver T and the result R should be different.

inline fun <T, R> T.whatIfMap(given: Boolean?, whatIf: (T) -> R, whatIfNot: (T) -> R): R

An expression for invoking whatIf when the given boolean value. If the given boolean is false, whatIfNot will be invoked instead of the whatIf. It is useful when the receiver T and the result R should be different.

Link copied to clipboard
inline fun <T> T?.whatIfNotNull(whatIf: (T) -> Unit): T?

An expression for invoking whatIf when the T target object is not null.

inline fun <T> T?.whatIfNotNull(whatIf: (T) -> Unit, whatIfNot: () -> Unit): T?

An expression for invoking whatIf when the T target object is not null. If the T target is null, whatIfNot will be invoked instead of the whatIf.

Link copied to clipboard
inline fun <R> Any?.whatIfNotNullAs(whatIf: (R) -> Unit): Any?

An expression for invoking whatIf when the target object is not null. If the target is not null and the target can be cast by the desired type R, the receiver will get a casted R type.

inline fun <R> Any?.whatIfNotNullAs(whatIf: (R) -> Unit, whatIfNot: () -> Unit): Any?

An expression for invoking whatIf when the target object is not null. If the target is not null and the target can be cast by the desired type R, the receiver will get a casted R type. If the target is null, whatIfNot will be invoked instead of the whatIf without casting.

Link copied to clipboard
inline fun <T> Array<out T>?.whatIfNotNullOrEmpty(whatIf: (Array<out T>) -> Unit): Array<out T>?

An expression for invoking whatIf when the Array is not null and not empty.

inline fun BooleanArray?.whatIfNotNullOrEmpty(whatIf: (BooleanArray) -> Unit): BooleanArray?

An expression for invoking whatIf when the BooleanArray is not null and not empty.

inline fun ByteArray?.whatIfNotNullOrEmpty(whatIf: (ByteArray) -> Unit): ByteArray?

An expression for invoking whatIf when the ByteArray is not null and not empty.

inline fun CharArray?.whatIfNotNullOrEmpty(whatIf: (CharArray) -> Unit): CharArray?

An expression for invoking whatIf when the CharArray is not null and not empty.

inline fun DoubleArray?.whatIfNotNullOrEmpty(whatIf: (DoubleArray) -> Unit): DoubleArray?

An expression for invoking whatIf when the DoubleArray is not null and not empty.

inline fun FloatArray?.whatIfNotNullOrEmpty(whatIf: (FloatArray) -> Unit): FloatArray?

An expression for invoking whatIf when the FloatArray is not null and not empty.

inline fun IntArray?.whatIfNotNullOrEmpty(whatIf: (IntArray) -> Unit): IntArray?

An expression for invoking whatIf when the IntArray is not null and not empty.

inline fun LongArray?.whatIfNotNullOrEmpty(whatIf: (LongArray) -> Unit): LongArray?

An expression for invoking whatIf when the LongArray is not null and not empty.

inline fun ShortArray?.whatIfNotNullOrEmpty(whatIf: (ShortArray) -> Unit): ShortArray?

An expression for invoking whatIf when the ShortArray is not null and not empty.

inline fun String?.whatIfNotNullOrEmpty(whatIf: (String) -> Unit): String?

An expression for invoking whatIf when the String is not null and not empty.

inline fun <T> List<T>?.whatIfNotNullOrEmpty(whatIf: (List<T>) -> Unit): List<T>?

An expression for invoking whatIf when the List is not null and not empty.

inline fun <T, R> Map<T, R>?.whatIfNotNullOrEmpty(whatIf: (Map<T, R>) -> Unit): Map<T, R>?

An expression for invoking whatIf when the Map is not null and not empty.

inline fun <T> Set<T>?.whatIfNotNullOrEmpty(whatIf: (Set<T>) -> Unit): Set<T>?

An expression for invoking whatIf when the Set is not null and not empty.

inline fun <T> Array<out T>?.whatIfNotNullOrEmpty(whatIf: (Array<out T>) -> Unit, whatIfNot: () -> Unit): Array<out T>?

An expression for invoking whatIf when the Array is not null and not empty. If the array is null or empty, whatIfNot will be invoked instead of the whatIf.

inline fun BooleanArray?.whatIfNotNullOrEmpty(whatIf: (BooleanArray) -> Unit, whatIfNot: () -> Unit): BooleanArray?

An expression for invoking whatIf when the BooleanArray is not null and not empty. If the array is null or empty, whatIfNot will be invoked instead of the whatIf.

inline fun ByteArray?.whatIfNotNullOrEmpty(whatIf: (ByteArray) -> Unit, whatIfNot: () -> Unit): ByteArray?

An expression for invoking whatIf when the ByteArray is not null and not empty. If the array is null or empty, whatIfNot will be invoked instead of the whatIf.

inline fun CharArray?.whatIfNotNullOrEmpty(whatIf: (CharArray) -> Unit, whatIfNot: () -> Unit): CharArray?

An expression for invoking whatIf when the CharArray is not null and not empty. If the array is null or empty, whatIfNot will be invoked instead of the whatIf.

inline fun DoubleArray?.whatIfNotNullOrEmpty(whatIf: (DoubleArray) -> Unit, whatIfNot: () -> Unit): DoubleArray?

An expression for invoking whatIf when the DoubleArray is not null and not empty. If the array is null or empty, whatIfNot will be invoked instead of the whatIf.

inline fun FloatArray?.whatIfNotNullOrEmpty(whatIf: (FloatArray) -> Unit, whatIfNot: () -> Unit): FloatArray?

An expression for invoking whatIf when the FloatArray is not null and not empty. If the array is null or empty, whatIfNot will be invoked instead of the whatIf.

inline fun IntArray?.whatIfNotNullOrEmpty(whatIf: (IntArray) -> Unit, whatIfNot: () -> Unit): IntArray?

An expression for invoking whatIf when the IntArray is not null and not empty. If the array is null or empty, whatIfNot will be invoked instead of the whatIf.

inline fun LongArray?.whatIfNotNullOrEmpty(whatIf: (LongArray) -> Unit, whatIfNot: () -> Unit): LongArray?

An expression for invoking whatIf when the LongArray is not null and not empty. If the array is null or empty, whatIfNot will be invoked instead of the whatIf.

inline fun ShortArray?.whatIfNotNullOrEmpty(whatIf: (ShortArray) -> Unit, whatIfNot: () -> Unit): ShortArray?

An expression for invoking whatIf when the ShortArray is not null and not empty. If the array is null or empty, whatIfNot will be invoked instead of the whatIf.

inline fun String?.whatIfNotNullOrEmpty(whatIf: (String) -> Unit, whatIfNot: () -> Unit): String?

An expression for invoking whatIf when the String is not null and not empty. If the array is null or empty, whatIfNot will be invoked instead of the whatIf.

inline fun <T> List<T>?.whatIfNotNullOrEmpty(whatIf: (List<T>) -> Unit, whatIfNot: () -> Unit): List<T>?

An expression for invoking whatIf when the List is not null and not empty. If the array is null or empty, whatIfNot will be invoked instead of the whatIf

inline fun <T, R> Map<T, R>?.whatIfNotNullOrEmpty(whatIf: (Map<T, R>) -> Unit, whatIfNot: () -> Unit): Map<T, R>?

An expression for invoking whatIf when the Map is not null and not empty. If the array is null or empty, whatIfNot will be invoked instead of the whatIf.

inline fun <T> Set<T>?.whatIfNotNullOrEmpty(whatIf: (Set<T>) -> Unit, whatIfNot: () -> Unit): Set<T>?

An expression for invoking whatIf when the Set is not null and not empty. If the array is null or empty, whatIfNot will be invoked instead of the whatIf.

Link copied to clipboard
inline fun <T, R> T?.whatIfNotNullWith(whatIf: (T) -> R, whatIfNot: (T?) -> R): R

An expression for invoking whatIf when the T target object is not null. If the T target is null, whatIfNot will be invoked instead of the whatIf. It is useful when the receiver T and the result R should be different.

Link copied to clipboard
inline fun Iterable<Boolean?>.whatIfOr(whatIf: () -> Unit): Iterable<Boolean?>
inline fun Iterable<Boolean?>.whatIfOr(whatIf: () -> Unit, whatIfNot: () -> Unit): Iterable<Boolean?>

An expression for operating Or operator to a list of the nullable-Boolean.

inline fun Boolean?.whatIfOr(predicate: Boolean?, whatIf: () -> Unit): Boolean?

An expression for invoking whatIf when the target Boolean is true or the predicate is true.