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

UpperCaseChar

class UpperCaseChar

UpperCaseChar constrains Char to a uppercase char

Safe nullable construction

import arrow.refinement.chars.UpperCaseChar

UpperCaseChar.orNull('A')
// UpperCaseChar(value=A)
UpperCaseChar.orNull('a')
UpperCaseChar.orNull('%')

Resolved constraints

UpperCaseChar.constraints('A')
// [(true, Expected A to be lower case)]
UpperCaseChar.constraints('a')
// [(false, Expected a to be lower case)]
UpperCaseChar.isValid('A')
// true
UpperCaseChar.isValid('a')
// false
UpperCaseChar.isValid('%')
// false

Folding validation

UpperCaseChar.fold('A', { "failed: $it" }, { "success: $it" })
// success: UpperCaseChar(value=A)
UpperCaseChar.fold('a', { "failed: $it" }, { "success: $it" })
// failed: [(false, Expected a to be lower case)]
UpperCaseChar.fold('%', { "failed: $it" }, { "success: $it" })
// failed: [(false, Expected % to be lower case)]

Unsafe require

UpperCaseChar.require('A')
// A
try { UpperCaseChar.require('a') } catch (e: IllegalArgumentException) { e.message }
// Expected a to be lower case

Types

Companion companion object Companion : Refined<Char, UpperCaseChar>

Properties

value val value: Char

Do you like Arrow?

Arrow Org
<