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

PositiveInt

class PositiveInt

PositiveInt constrains an Int to be > 0

Safe nullable construction

import arrow.refinement.numbers.PositiveInt

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

Resolved constraints

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

Folding validation

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

Unsafe require

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

Types

Companion companion object Companion : Refined<Int, PositiveInt>

Properties

value val value: Int

Do you like Arrow?

Arrow Org
<