ensure

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

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

import arrow.core.Either
import arrow.core.continuations.eagerEffect
import io.kotest.matchers.shouldBe

fun main() {
val condition = true
val failure = "failed"
val int = 4
eagerEffect<String, Int> {
ensure(condition) { failure }
int
}.toEither() shouldBe if(condition) Either.Right(int) else Either.Left(failure)
}