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

Rfc5737Testnet2Network

class Rfc5737Testnet2Network

Rfc5737Testnet2Network constrains String to be an IPv4 that StartsWith 198.51.100.

Safe nullable construction

import arrow.refinement.network.Rfc5737Testnet2Network

Rfc5737Testnet2Network.orNull("198.51.100.1")
// 198.51.100.1
Rfc5737Testnet2Network.orNull("80.34.200.60")

Resolved constraints

Rfc5737Testnet2Network.constraints("198.51.100.1")
// [(true, Expected 198.51.100.1 to be an IPv4 address), (true, Expected 198.51.100.1 to start with 198.51.100.)]
Rfc5737Testnet2Network.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 198.51.100.)]
Rfc5737Testnet2Network.isValid("198.51.100.1")
// true
Rfc5737Testnet2Network.isValid("80.34.200.60")
// false

Folding validation

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

Unsafe require

try { Rfc5737Testnet2Network.require("80.34.200.60") } catch (e: IllegalArgumentException) { e.message }
// Expected 80.34.200.60 to start with 198.51.100.
Rfc5737Testnet2Network.require("198.51.100.1")
// 198.51.100.1

Types

Companion companion object Companion : Refined<String, Rfc5737Testnet2Network>

Properties

value val value: String

Do you like Arrow?

Arrow Org
<