ensure Not Null
Deprecated
Replaced by Raise, replace arrow.core.computations.ensureNotNull to arrow.core.raise.ensureNotNull
Replace with
import import arrow.core.raise.ensureNotNull
ensureNotNull(value, orLeft)
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
Replaced by Raise, replace arrow.core.computations.ensureNotNull to arrow.core.raise.ensureNotNull
Replace with
import import arrow.core.raise.ensureNotNull
ensureNotNull(value)
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.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: null
Deprecated
Replaced by Raise, replace arrow.core.computations.ensureNotNull to arrow.core.raise.ensureNotNull
Replace with
import import arrow.core.raise.ensureNotNull
ensureNotNull(value)
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