arrow-refined-types / arrow.refinement.strings / ValidLong

ValidLong

class ValidLong

ValidLong constrains String to be a valid Long

Safe nullable construction

import arrow.refinement.strings.ValidLong

ValidLong.orNull("10")
// 10
ValidLong.orNull("abc")

Resolved constraints

ValidLong.constraints("10")
// [(true, Expected 10 to be a valid Long)]
ValidLong.constraints("abc")
// [(false, Expected abc to be a valid Long)]
ValidLong.isValid("10")
// true
ValidLong.isValid("abc")
// false

Folding validation

ValidLong.fold("10", { "failed: $it" }, { "success: $it" })
// success: ValidLong(value=10)
ValidLong.fold("abc", { "failed: $it" }, { "success: $it" })
// failed: [(false, Expected abc to be a valid Long)]

Unsafe require

ValidLong.require("10")
// 10
try { ValidLong.require("abc") } catch (e: IllegalArgumentException) { e.message }
// Expected abc to be a valid Long

Types

Companion companion object Companion : Refined<String, ValidLong>

Properties

value val value: String

Do you like Arrow?

Arrow Org
<