ensure
Ensure check if the value is true
, and if it is it allows the option { }
binding to continue. In case it is false
, then it short-circuits the binding and returns None.
import arrow.core.computations.option
//sampleStart
suspend fun main() {
option<Int> {
ensure(true)
println("ensure(true) passes")
ensure(false)
1
}
//sampleEnd
.let(::println)
}
// println: "ensure(true) passes"
// res: None
Content copied to clipboard