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

Minute

class Minute

Minute constrains an Int to be in range of 0..59

Safe nullable construction

import arrow.refinement.time.Minute

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

Resolved constraints

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

Folding validation

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

Unsafe require

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

Types

Companion companion object Companion : Refined<Int, Minute>

Properties

value val value: Int

Do you like Arrow?

Arrow Org
<