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

Even

class Even

Even constrains an Int to be DivisibleBy by 2

Safe nullable construction

import arrow.refinement.numbers.Even

Even.orNull(2)
// Even(value=2)
Even.orNull(1)

Resolved constraints

Even.constraints(2)
// [(true, 2 should be even)]
Even.constraints(1)
// [(false, 1 should be even)]
Even.isValid(2)
// true
Even.isValid(1)
// false

Folding validation

Even.fold(2, { "failed: $it" }, { "success: $it" })
// success: Even(value=2)
Even.fold(1, { "failed: $it" }, { "success: $it" })
// failed: [(false, 1 should be even)]

Unsafe require

Even.require(2)
// 2
try { Even.require(1) } catch (e: IllegalArgumentException) { e.message }
// 1 should be even

Types

Companion companion object Companion : Refined<Int, Even>

Properties

value val value: Int

Do you like Arrow?

Arrow Org
<