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

From

class From

From constrains Int to be >= N

Safe nullable construction

import arrow.refinement.numbers.From

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

Resolved constraints

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

Folding validation

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

Unsafe require

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

Types

N class N : Refined<Int, From>

Properties

value val value: Int

Do you like Arrow?

Arrow Org
<