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

IPv4

class IPv4

IPv4 constrains String to be a valid IPv4

Safe nullable construction

import arrow.refinement.strings.IPv4

IPv4.orNull("192.168.1.1")
// 192.168.1.1
IPv4.orNull("abc")

Resolved constraints

IPv4.constraints("192.168.1.1")
// [(true, Expected 192.168.1.1 to be an IPv4 address)]
IPv4.constraints("abc")
// [(false, Expected abc to be an IPv4 address)]
IPv4.isValid("192.168.1.1")
// true
IPv4.isValid("abc")
// false

Folding validation

IPv4.fold("192.168.1.1", { "failed: $it" }, { "success: $it" })
// success: IPv4(value=192.168.1.1)
IPv4.fold("abc", { "failed: $it" }, { "success: $it" })
// failed: [(false, Expected abc to be an IPv4 address)]

Unsafe require

IPv4.require("192.168.1.1")
// 192.168.1.1
try { IPv4.require("abc") } catch (e: IllegalArgumentException) { e.message }
// Expected abc to be an IPv4 address

Types

Companion companion object Companion : Refined<String, IPv4>

Properties

value val value: String

Companion Object Properties

IPV4Regex Credit for regex goes to https://mkyong.com/regular-expressions/how-to-validate-ip-address-with-regular-expression/val IPV4Regex: <ERROR CLASS>

Do you like Arrow?

Arrow Org
<