validate
Runs some validation, expressed as a lambda that may raise, on Right values. If the validation is successful, the value is left unchanged. The main use case is in combination with ensure and other validation functions.
import arrow.core.Either
import arrow.core.raise.ensure
import io.kotest.matchers.shouldBe
fun test() {
val one: Either<String, Int> = Either.Right(1)
one.validate { ensure(it > 0) { "negative" } } shouldBe one
val zero: Either<String, Int> = Either.Right(0)
zero.validate { ensure(it > 0) { "negative" } } shouldBe Either.Left("negative")
}Content copied to clipboard