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