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

Month

class Month

Month constrains an Int to be in range of 1..12

Safe nullable construction

import arrow.refinement.time.Month

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

Resolved constraints

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

Folding validation

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

Unsafe require

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

Types

Companion companion object Companion : Refined<Int, Month>

Properties

value val value: Int

Do you like Arrow?

Arrow Org
<