arrow-refined-types / arrow.refinement.chars / Digit

Digit

class Digit

Digit constrains Char to a decimal digit number

Safe nullable construction

import arrow.refinement.chars.Digit

Digit.orNull('1')
// Digit(value=1)
Digit.orNull('a')

Resolved constraints

Digit.constraints('1')
// [(true, Expected 1 to be a digit)]
Digit.constraints('a')
// [(false, Expected a to be a digit)]
Digit.isValid('1')
// true
Digit.isValid('a')
// false

Folding validation

Digit.fold('1', { "failed: $it" }, { "success: $it" })
// success: Digit(value=1)
Digit.fold('a', { "failed: $it" }, { "success: $it" })
// failed: [(false, Expected a to be a digit)]

Unsafe require

Digit.require('1')
// 1
try { Digit.require('a') } catch (e: IllegalArgumentException) { e.message }
// Expected a to be a digit

Types

Companion companion object Companion : Refined<Char, Digit>

Properties

value val value: Char

Do you like Arrow?

Arrow Org
<