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

ValidBigDecimal

class ValidBigDecimal

JVM only

ValidBigDecimal constrains String to be a valid java.math.BigDecimal

Safe nullable construction

import arrow.refinement.strings.ValidBigDecimal

ValidBigDecimal.orNull("10000.0000033")
// 10000.0000033
ValidBigDecimal.orNull("abc")

Resolved constraints

ValidBigDecimal.constraints("10000.0000033")
// [(true, Expected 10000.0000033 to be a valid BigDecimal)]
ValidBigDecimal.constraints("abc")
// [(false, Expected abc to be a valid BigDecimal)]
ValidBigDecimal.isValid("10000.0000033")
// true
ValidBigDecimal.isValid("abc")
// false

Folding validation

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

Unsafe require

ValidBigDecimal.require("10000.0000033")
// 10000.0000033
try { ValidBigDecimal.require("abc") } catch (e: IllegalArgumentException) { e.message }
// Expected abc to be a valid BigDecimal

Types

Companion companion object Companion : Refined<String, ValidBigDecimal>

Properties

value val value: String

Do you like Arrow?

Arrow Org
<