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

Second

class Second

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

Safe nullable construction

import arrow.refinement.time.Second

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

Resolved constraints

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

Folding validation

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

Unsafe require

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

Types

Companion companion object Companion : Refined<Int, Second>

Properties

value val value: Int

Do you like Arrow?

Arrow Org
<