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

NegativeInt

class NegativeInt

NegativeInt constrains an Int to be < 0

Safe nullable construction

import arrow.refinement.numbers.NegativeInt

NegativeInt.orNull(2)
NegativeInt.orNull(-1)
// NegativeInt(value=-1)

Resolved constraints

NegativeInt.constraints(2)
// [(false, 2 should be < 0)]
NegativeInt.constraints(-1)
// [(true, -1 should be < 0)]
NegativeInt.isValid(2)
// false
NegativeInt.isValid(-1)
// true

Folding validation

NegativeInt.fold(2, { "failed: $it" }, { "success: $it" })
// failed: [(false, 2 should be < 0)]
NegativeInt.fold(-1, { "failed: $it" }, { "success: $it" })
// success: NegativeInt(value=-1)

Unsafe require

NegativeInt.require(-1)
// -1
try { NegativeInt.require(2) } catch (e: IllegalArgumentException) { e.message }
// 2 should be < 0

Types

Companion companion object Companion : Refined<Int, NegativeInt>

Properties

value val value: Int

Do you like Arrow?

Arrow Org
<