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

StartsWith

class StartsWith

StartsWith constrains String to start with Value

Safe nullable construction

import arrow.refinement.strings.StartsWith

StartsWith.Value("hello").orNull("hello world")
// hello world
StartsWith.Value("hello").orNull("abc")

Resolved constraints

StartsWith.Value("hello").constraints("hello world")
// [(true, Expected hello world to start with hello)]
StartsWith.Value("hello").constraints("abc")
// [(false, Expected abc to start with hello)]
StartsWith.Value("hello").isValid("hello world")
// true
StartsWith.Value("hello").isValid("abc")
// false

Folding validation

StartsWith.Value("hello").fold("hello world", { "failed: $it" }, { "success: $it" })
// success: StartsWith(value=hello world)
StartsWith.Value("hello").fold("abc", { "failed: $it" }, { "success: $it" })
// failed: [(false, Expected abc to start with hello)]

Unsafe require

StartsWith.Value("hello").require("hello world")
// hello world
try { StartsWith.Value("hello").require("abc") } catch (e: IllegalArgumentException) { e.message }
// Expected abc to start with hello

Types

Value class Value : Refined<String, StartsWith>

Properties

value val value: String

Do you like Arrow?

Arrow Org
<