![JAR search and dependency download from the Maven repository](/logo.png)
gnese.kotlin-result-ext.0.1.source-code.option.kt Maven / Gradle / Ivy
fun T?.isSome(): Boolean = this != null
fun T?.isNull(): Boolean = !isSome()
fun T?.map(block: (T) -> U): U? = this?.let(block)
fun T?.mapOr(default: U, block: (T) -> U): U = map(block) ?: default
fun T?.mapOrElse(default: () -> U, block: (T) -> U): U = map(block) ?: default()
fun T?.successOr(failure: F): Result =
if (this != null) {
Result.success(this)
} else {
Result.failure(failure)
}
fun T?.successOrElse(failure: () -> F): Result =
if (this != null) {
Result.success(this)
} else {
Result.failure(failure())
}
fun T?.and(other: U?): U? = this?.let { other }
fun T?.filter(block: (T) -> Boolean): T? = this?.let(block)?.let { if (it) this else null }
fun T?.or(other: T?): T? = this ?: other
fun T?.orElse(block: () -> T?) = this ?: block()
© 2015 - 2025 Weber Informatics LLC | Privacy Policy