All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.hnau.base.extensions.NullableIfExtensions.kt Maven / Gradle / Ivy

There is a newer version: 2.1.9
Show newest version
package org.hnau.base.extensions


/**
 * Return result of executing [ifNotNull] if not null, or result of executing [ifNull]
 */
inline fun  T?.checkNullable(ifNotNull: (T) -> R, ifNull: () -> R) =
        if (this != null) ifNotNull(this) else ifNull()

/**
 * Return result of executing [ifNull] if null or return null
 */
inline fun  T.ifNull(ifNull: () -> R) =
        checkNullable({ null }, ifNull)

/**
 * Return result of executing [ifNotNull] if not null or return null
 */
inline fun  T?.ifNotNull(ifNotNull: (T) -> R) =
        checkNullable(ifNotNull, { null })

/**
 * Return [this] if not null, or result of executing [ifNull]
 */
inline fun  T?.elvis(ifNull: () -> T) = this ?: ifNull()

inline fun  isNullable() = null is T

fun  T?.sureNotNull() = this!!




© 2015 - 2025 Weber Informatics LLC | Privacy Policy