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

LessThan

class LessThan

LessThan constrains Int to be < N

Safe nullable construction

import arrow.refinement.numbers.LessThan

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

Resolved constraints

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

Folding validation

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

Unsafe require

LessThan.N(1u).require(0)
// 0
try { LessThan.N(1u).require(1) } catch (e: IllegalArgumentException) { e.message }
// 1 should be less than 1

Types

N class N : Refined<Int, LessThan>

Properties

value val value: Int

Do you like Arrow?

Arrow Org
<