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

HexString

class HexString

HexString constrains String to be a valid hexadecimal string

Safe nullable construction

import arrow.refinement.strings.HexString

HexString.orNull("fd00000aa866")
// fd00000aa866
HexString.orNull("abc")
// abc

Resolved constraints

HexString.constraints("fd00000aa866")
// [(true, Expected fd00000aa866 to be a valid hexadecimal string)]
HexString.constraints("abc")
// [(true, Expected abc to be a valid hexadecimal string)]
HexString.isValid("fd00000aa866")
// true
HexString.isValid("abc")
// true

Folding validation

HexString.fold("fd00000aa866", { "failed: $it" }, { "success: $it" })
// success: HexString(value=fd00000aa866)
HexString.fold("abc", { "failed: $it" }, { "success: $it" })
// success: HexString(value=abc)

Unsafe require

HexString.require("fd00000aa866")
// fd00000aa866
try { HexString.require("abc") } catch (e: IllegalArgumentException) { e.message }
// HexString(value=abc)

Types

Companion companion object Companion : Refined<String, HexString>

Properties

value val value: String

Do you like Arrow?

Arrow Org
<