arrow-refined-types / arrow.refinement.time / Day

Day

class Day

Day constrains an Int to be in range of 1..31

Safe nullable construction

import arrow.refinement.time.Day

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

Resolved constraints

Day.constraints(2)
// [(true, 2 should be in the closed range of 1..31 to be a valid day number)]
Day.constraints(-1)
// [(false, -1 should be in the closed range of 1..31 to be a valid day number)]
Day.isValid(2)
// true
Day.isValid(-1)
// false

Folding validation

Day.fold(2, { "failed: $it" }, { "success: $it" })
// success: Day(value=2)
Day.fold(-1, { "failed: $it" }, { "success: $it" })
// failed: [(false, -1 should be in the closed range of 1..31 to be a valid day number)]

Unsafe require

Day.require(2)
// 2
try { Day.require(-1) } catch (e: IllegalArgumentException) { e.message }
// -1 should be in the closed range of 1..31 to be a valid day number

Types

Companion companion object Companion : Refined<Int, Day>

Properties

value val value: Int

Do you like Arrow?

Arrow Org
<