ensure

open suspend fun ensure(condition: Boolean, shift: () -> R)

ensure that condition is true, if it's false it will shift with the provided value R. Monadic version of kotlin.require.

suspend fun test() = checkAll(Arb.boolean(), Arb.string(), Arb.int()) { condition, failure, int ->
cont<String, Int> {
ensure(condition) { failure }
int
}.toEither() shouldBe if(condition) Either.Right(int) else Either.Left(failure)
}

Sources

common source
Link copied to clipboard