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

Letter

class Letter

Letter constrains Char to a letter

Safe nullable construction

import arrow.refinement.chars.Letter

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

Resolved constraints

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

Folding validation

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

Unsafe require

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

Types

Companion companion object Companion : Refined<Char, Letter>

Properties

value val value: Char

Do you like Arrow?

Arrow Org
<