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

LetterOrDigit

class LetterOrDigit

LetterOrDigit constrains Char to a decimal digit number or a letter

Safe nullable construction

import arrow.refinement.chars.LetterOrDigit

LetterOrDigit.orNull('1')
// LetterOrDigit(value=1)
LetterOrDigit.orNull('a')
// LetterOrDigit(value=a)
LetterOrDigit.orNull('%')

Resolved constraints

LetterOrDigit.constraints('1')
// [(true, Expected 1 to be a letter or digit)]
LetterOrDigit.constraints('a')
// [(true, Expected a to be a letter or digit)]
LetterOrDigit.isValid('1')
// true
LetterOrDigit.isValid('a')
// true
LetterOrDigit.isValid('%')
// false

Folding validation

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

Unsafe require

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

Types

Companion companion object Companion : Refined<Char, LetterOrDigit>

Properties

value val value: Char

Do you like Arrow?

Arrow Org
<