arrow-refined-types / arrow.refinement.network / Rfc5737Testnet1Network

Rfc5737Testnet1Network

class Rfc5737Testnet1Network

Rfc5737Testnet1Network constrains String to be an IPv4 that StartsWith 192.0.2.

Safe nullable construction

import arrow.refinement.network.Rfc5737Testnet1Network

Rfc5737Testnet1Network.orNull("192.0.2.1")
// 192.0.2.1
Rfc5737Testnet1Network.orNull("80.34.200.60")

Resolved constraints

Rfc5737Testnet1Network.constraints("192.0.2.1")
// [(true, Expected 192.0.2.1 to be an IPv4 address), (true, Expected 192.0.2.1 to start with 192.0.2.)]
Rfc5737Testnet1Network.constraints("80.34.200.60")
// [(true, Expected 80.34.200.60 to be an IPv4 address), (false, Expected 80.34.200.60 to start with 192.0.2.)]
Rfc5737Testnet1Network.isValid("192.0.2.1")
// true
Rfc5737Testnet1Network.isValid("80.34.200.60")
// false

Folding validation

Rfc5737Testnet1Network.fold("192.0.2.1", { "failed: $it" }, { "success: $it" })
// success: Rfc5737Testnet1Network(value=192.0.2.1)
Rfc5737Testnet1Network.fold("80.34.200.60", { "failed: $it" }, { "success: $it" })
// failed: [(false, Expected 80.34.200.60 to start with 192.0.2.)]

Unsafe require

try { Rfc5737Testnet1Network.require("80.34.200.60") } catch (e: IllegalArgumentException) { e.message }
// Expected 80.34.200.60 to start with 192.0.2.
Rfc5737Testnet1Network.require("192.0.2.1")
// 192.0.2.1

Types

Companion companion object Companion : Refined<String, Rfc5737Testnet1Network>

Properties

value val value: String

Do you like Arrow?

Arrow Org
<