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

Hour

class Hour

Hour constrains an Int to be in range of 0..23

Safe nullable construction

import arrow.refinement.time.Hour

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

Resolved constraints

Hour.constraints(2)
// [(true, 2 should be in the closed range of 0..23 to be a valid hour number)]
Hour.constraints(-1)
// [(false, -1 should be in the closed range of 0..23 to be a valid hour number)]
Hour.isValid(2)
// true
Hour.isValid(-1)
// false

Folding validation

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

Unsafe require

Hour.require(2)
// 2
try { Hour.require(-1) } catch (e: IllegalArgumentException) { e.message }
// -1 should be in the closed range of 0..23 to be a valid hour number

Types

Companion companion object Companion : Refined<Int, Hour>

Properties

value val value: Int

Do you like Arrow?

Arrow Org
<