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

ValidInt

class ValidInt

ValidInt constrains String to be a valid Int

Safe nullable construction

import arrow.refinement.strings.ValidInt

ValidInt.orNull("10")
// 10
ValidInt.orNull("abc")

Resolved constraints

ValidInt.constraints("10")
// [(true, Expected 10 to be a valid Int)]
ValidInt.constraints("abc")
// [(false, Expected abc to be a valid Int)]
ValidInt.isValid("10")
// true
ValidInt.isValid("abc")
// false

Folding validation

ValidInt.fold("10", { "failed: $it" }, { "success: $it" })
// success: ValidInt(value=10)
ValidInt.fold("abc", { "failed: $it" }, { "success: $it" })
// failed: [(false, Expected abc to be a valid Int)]

Unsafe require

ValidInt.require("10")
// 10
try { ValidInt.require("abc") } catch (e: IllegalArgumentException) { e.message }
// Expected abc to be a valid Int

Types

Companion companion object Companion : Refined<String, ValidInt>

Properties

value val value: String

Do you like Arrow?

Arrow Org
<