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

ValidBigInt

class ValidBigInt

JVM only

ValidBigInt constrains String to be a valid java.math.BigInteger

Safe nullable construction

import arrow.refinement.strings.ValidBigInt

ValidBigInt.orNull("10000000003334534553445345")
// 10000000003334534553445345
ValidBigInt.orNull("abc")

Resolved constraints

ValidBigInt.constraints("10000000003334534553445345")
// [(true, Expected 10000000003334534553445345 to be a valid BigInt)]
ValidBigInt.constraints("abc")
// [(false, Expected abc to be a valid BigInt)]
ValidBigInt.isValid("10000000003334534553445345")
// true
ValidBigInt.isValid("abc")
// false

Folding validation

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

Unsafe require

ValidBigInt.require("10000000003334534553445345")
// 10000000003334534553445345
try { ValidBigInt.require("abc") } catch (e: IllegalArgumentException) { e.message }
// Expected abc to be a valid BigInt

Types

Companion companion object Companion : Refined<String, ValidBigInt>

Properties

value val value: String

Do you like Arrow?

Arrow Org
<