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

ValidDouble

class ValidDouble

ValidDouble constrains String to be a valid Double

Safe nullable construction

import arrow.refinement.strings.ValidDouble

ValidDouble.orNull("10.0")
// 10.0
ValidDouble.orNull("abc")

Resolved constraints

ValidDouble.constraints("10.0")
// [(true, Expected 10.0 to be a valid Double)]
ValidDouble.constraints("abc")
// [(false, Expected abc to be a valid Double)]
ValidDouble.isValid("10.0")
// true
ValidDouble.isValid("abc")
// false

Folding validation

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

Unsafe require

ValidDouble.require("10.0")
// 10.0
try { ValidDouble.require("abc") } catch (e: IllegalArgumentException) { e.message }
// Expected abc to be a valid Double

Types

Companion companion object Companion : Refined<String, ValidDouble>

Properties

value val value: String

Do you like Arrow?

Arrow Org
<