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

Rfc3927LocalLinkNetwork

class Rfc3927LocalLinkNetwork

Rfc3927LocalLinkNetwork constrains String to be an IPv4 that StartsWith 169.254.

Safe nullable construction

import arrow.refinement.network.Rfc3927LocalLinkNetwork

Rfc3927LocalLinkNetwork.orNull("169.254.0.1")
// 169.254.0.1
Rfc3927LocalLinkNetwork.orNull("80.34.200.60")

Resolved constraints

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

Folding validation

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

Unsafe require

try { Rfc3927LocalLinkNetwork.require("80.34.200.60") } catch (e: IllegalArgumentException) { e.message }
// Expected 80.34.200.60 to start with 169.254.
Rfc3927LocalLinkNetwork.require("169.254.0.1")
// 169.254.0.1

Types

Companion companion object Companion : Refined<String, Rfc3927LocalLinkNetwork>

Properties

value val value: String

Do you like Arrow?

Arrow Org
<