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

Odd

class Odd

Odd constrains an Int to not be Even

Safe nullable construction

import arrow.refinement.numbers.Odd

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

Resolved constraints

Odd.constraints(2)
// [(false, 2 should be odd)]
Odd.constraints(1)
// [(true, 1 should be odd)]
Odd.isValid(2)
// false
Odd.isValid(1)
// true

Folding validation

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

Unsafe require

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

Types

Companion companion object Companion : Refined<Int, Odd>

Properties

value val value: Int

Do you like Arrow?

Arrow Org
<