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

IPv6

class IPv6

IPv6 constrains String to be a valid IPv6

Safe nullable construction

import arrow.refinement.strings.IPv6

IPv6.orNull("2001:0db8:85a3:0000:0000:8a2e:0370:7334")
// 2001:0db8:85a3:0000:0000:8a2e:0370:7334
IPv6.orNull("abc")

Resolved constraints

IPv6.constraints("2001:0db8:85a3:0000:0000:8a2e:0370:7334")
// [(true, Expected 2001:0db8:85a3:0000:0000:8a2e:0370:7334 to be an IPv6 address)]
IPv6.constraints("abc")
// [(false, Expected abc to be an IPv6 address)]
IPv6.isValid("2001:0db8:85a3:0000:0000:8a2e:0370:7334")
// true
IPv6.isValid("abc")
// false

Folding validation

IPv6.fold("2001:0db8:85a3:0000:0000:8a2e:0370:7334", { "failed: $it" }, { "success: $it" })
// success: IPv6(value=2001:0db8:85a3:0000:0000:8a2e:0370:7334)
IPv6.fold("abc", { "failed: $it" }, { "success: $it" })
// failed: [(false, Expected abc to be an IPv6 address)]

Unsafe require

IPv6.require("2001:0db8:85a3:0000:0000:8a2e:0370:7334")
// 2001:0db8:85a3:0000:0000:8a2e:0370:7334
try { IPv6.require("abc") } catch (e: IllegalArgumentException) { e.message }
// Expected abc to be an IPv6 address

Types

Companion companion object Companion : Refined<String, IPv6>

Properties

value val value: String

Companion Object Properties

IPV6Regex Credit for regex goes to https://stackoverflow.com/questions/53497/regular-expression-that-matches-valid-ipv6-addressesval IPV6Regex: <ERROR CLASS>

Do you like Arrow?

Arrow Org
<