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

To

class To

To constrains Int to be <= N

Safe nullable construction

import arrow.refinement.numbers.To

To.N(1u).orNull(2)
To.N(1u).orNull(0)
// To(value=0)

Resolved constraints

To.N(1u).constraints(2)
// [(false, 2 should be less than or equal to 1)]
To.N(1u).constraints(0)
// [(true, 0 should be less than or equal to 1)]
To.N(1u).isValid(2)
// false
To.N(1u).isValid(0)
// true

Folding validation

To.N(1u).fold(2, { "failed: $it" }, { "success: $it" })
// failed: [(false, 2 should be less than or equal to 1)]
To.N(1u).fold(0, { "failed: $it" }, { "success: $it" })
// success: To(value=0)

Unsafe require

To.N(1u).require(0)
// 0
try { To.N(1u).require(2) } catch (e: IllegalArgumentException) { e.message }
// 2 should be less than or equal to 1

Types

N class N : Refined<Int, To>

Properties

value val value: Int

Do you like Arrow?

Arrow Org
<