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

Rfc5737TestnetNetwork

class Rfc5737TestnetNetwork

Rfc5737TestnetNetwork constrains String to be either of Rfc5737Testnet1Network or Rfc5737Testnet2Network or Rfc5737Testnet3Network

Safe nullable construction

import arrow.refinement.network.Rfc5737TestnetNetwork

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

Resolved constraints

Rfc5737TestnetNetwork.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.)]
Rfc5737TestnetNetwork.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.), (false, Expected 80.34.200.60 to start with 198.51.100.), (false, Expected 80.34.200.60 to start with 203.0.113.)]
Rfc5737TestnetNetwork.isValid("192.0.2.1")
// true
Rfc5737TestnetNetwork.isValid("80.34.200.60")
// false

Folding validation

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

Unsafe require

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

Types

Companion companion object Companion : Refined<String, Rfc5737TestnetNetwork>

Properties

value val value: String

Do you like Arrow?

Arrow Org
<