arrow-refined-types / arrow.refinement.numbers / Zero

Zero

object Zero : Refined<Int, Zero>

Zero constrains an Int to be == 0

Safe nullable construction

import arrow.refinement.numbers.Zero

Zero.orNull(0)
// arrow.refinement.numbers.Zero@621453f7
Zero.orNull(-1)

Resolved constraints

Zero.constraints(0)
// [(true, Expected 0 to be 0)]
Zero.constraints(-1)
// [(false, Expected -1 to be 0)]
Zero.isValid(0)
// true
Zero.isValid(-1)
// false

Folding validation

Zero.fold(0, { "failed: $it" }, { "success: $it" })
// success: arrow.refinement.numbers.Zero@621453f7
Zero.fold(-1, { "failed: $it" }, { "success: $it" })
// failed: [(false, Expected -1 to be 0)]

Unsafe require

Zero.require(0)
// arrow.refinement.numbers.Zero@621453f7
try { Zero.require(-1) } catch (e: IllegalArgumentException) { e.message }
// Expected -1 to be 0

Properties

value const val value: Int

Extension Functions

toEither fun <V, R> Refined<V, R>.toEither(value: V): Either<String, R>
toValidated fun <V, R> Refined<V, R>.toValidated(value: V): Validated<String, R>
toValidatedNel fun <V, R> Refined<V, R>.toValidatedNel(value: V): ValidatedNel<String, R>

Do you like Arrow?

Arrow Org
<