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

NotZero

object NotZero : Refined<Int, NotZero>

NotZero constrains an Int to be != 0

Safe nullable construction

import arrow.refinement.numbers.NotZero

NotZero.orNull(0)
NotZero.orNull(-1)
// arrow.refinement.numbers.NotZero@2e14b65a

Resolved constraints

NotZero.constraints(0)
// [(false, should not be 0)]
NotZero.constraints(-1)
// [(true, should not be 0)]
NotZero.isValid(0)
// false
NotZero.isValid(-1)
// true

Folding validation

NotZero.fold(0, { "failed: $it" }, { "success: $it" })
// failed: [(false, should not be 0)]
NotZero.fold(-1, { "failed: $it" }, { "success: $it" })
// success: arrow.refinement.numbers.NotZero@2e14b65a

Unsafe require

NotZero.require(-1)
// arrow.refinement.numbers.NotZero@2e14b65a
try { NotZero.require(0) } catch (e: IllegalArgumentException) { e.message }
// should not be 0

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
<