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

Rfc1918ClassAPrivateNetwork

class Rfc1918ClassAPrivateNetwork

Rfc1918ClassAPrivateNetwork constrains String to an IPv4 that StartsWith 10.

Safe nullable construction

import arrow.refinement.network.Rfc1918ClassAPrivateNetwork

Rfc1918ClassAPrivateNetwork.orNull("10.0.0.1")
// 10.0.0.1
Rfc1918ClassAPrivateNetwork.orNull("80.34.200.60")

Resolved constraints

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

Folding validation

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

Unsafe require

try { Rfc1918ClassAPrivateNetwork.require("80.34.200.60") } catch (e: IllegalArgumentException) { e.message }
// Expected 80.34.200.60 to start with 10.
Rfc1918ClassAPrivateNetwork.require("10.0.0.1")
// 10.0.0.1

Types

Companion companion object Companion : Refined<String, Rfc1918ClassAPrivateNetwork>

Properties

value val value: String

Do you like Arrow?

Arrow Org
<