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@27d9cd79

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@27d9cd79

Unsafe require

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

Do you like Arrow?

Arrow Org
<