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

Size

class Size

Size constrains a string to be have N length

Safe nullable construction

import arrow.refinement.strings.Size

Size.N(1u).orNull("a")
// a
Size.N(1u).orNull("ab")

Resolved constraints

Size.N(1u).constraints("a")
// [(true, Expected a to have length 1)]
Size.N(1u).constraints("ab")
// [(false, Expected ab to have length 1)]
Size.N(1u).isValid("a")
// true
Size.N(1u).isValid("ab")
// false

Folding validation

Size.N(1u).fold("a", { "failed: $it" }, { "success: $it" })
// success: Size(value=a)
Size.N(1u).fold("ab", { "failed: $it" }, { "success: $it" })
// failed: [(false, Expected ab to have length 1)]

Unsafe require

Size.N(1u).require("a")
// a
try { Size.N(1u).require("ab") } catch (e: IllegalArgumentException) { e.message }
// Expected ab to have length 1

Types

N class N : Refined<String, Size>

Properties

value val value: String

Do you like Arrow?

Arrow Org
<