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

Rfc1918ClassCPrivateNetwork

class Rfc1918ClassCPrivateNetwork

Rfc1918ClassCPrivateNetwork constrains String to an IPv4 that StartsWith 192.168.

Safe nullable construction

import arrow.refinement.network.Rfc1918ClassCPrivateNetwork

Rfc1918ClassCPrivateNetwork.orNull("192.168.0.1")
// 192.168.0.1
Rfc1918ClassCPrivateNetwork.orNull("80.34.200.60")

Resolved constraints

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

Folding validation

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

Unsafe require

try { Rfc1918ClassCPrivateNetwork.require("80.34.200.60") } catch (e: IllegalArgumentException) { e.message }
// Expected 80.34.200.60 to start with 192.168.
Rfc1918ClassCPrivateNetwork.require("192.168.0.1")
// 192.168.0.1

Types

Companion companion object Companion : Refined<String, Rfc1918ClassCPrivateNetwork>

Properties

value val value: String

Do you like Arrow?

Arrow Org
<