ensure Not Null
Deprecated
Deprecated in favor of Effect DSL: EffectScope
Ensures that value is not null. When the value is not null, then it will be returned as non null and the check value is now smart-checked to non-null. Otherwise, if the value is null then the either binding will short-circuit with orLeft inside of Either.Left.
import arrow.core.computations.either
import arrow.core.computations.ensureNotNull
//sampleStart
suspend fun main() {
either<String, Int> {
val x: Int? = 1
ensureNotNull(x) { "passes" }
println(x)
ensureNotNull(null) { "failed" }
}
//sampleEnd
.let(::println)
}
// println: "1"
// res: Either.Left("failed")Deprecated
Deprecated in favor of Effect DSL: EffectScope
Replace with
import arrow.core.continuations.ensureNotNull
ensureNotNullEnsures that value is not null. When the value is not null, then it will be returned as non null and the check value is now smart-checked to non-null. Otherwise, if the value is null then the option binding will short-circuit with None.
import arrow.core.computations.nullable
import arrow.core.computations.ensureNotNull
//sampleStart
suspend fun main() {
nullable<Int> {
val x: Int? = 1
ensureNotNull(x)
println(x)
ensureNotNull(null)
}
//sampleEnd
.let(::println)
}
// println: "1"
// res: nullDeprecated
Deprecated in favor of Effect DSL: EffectScope
Ensures that value is not null. When the value is not null, then it will be returned as non null and the check value is now smart-checked to non-null. Otherwise, if the value is null then the option binding will short-circuit with None.
import arrow.core.computations.option
import arrow.core.computations.ensureNotNull
//sampleStart
suspend fun main() {
option<Int> {
val x: Int? = 1
ensureNotNull(x)
println(x)
ensureNotNull(null)
}
//sampleEnd
.let(::println)
}
// println: "1"
// res: None