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

Rfc1918ClassBPrivateNetwork

class Rfc1918ClassBPrivateNetwork

Rfc1918ClassBPrivateNetwork constrains String to an IPv4 that MatchesRegex ^172\\.(16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31)\\..+

Safe nullable construction

import arrow.refinement.network.Rfc1918ClassBPrivateNetwork

Rfc1918ClassBPrivateNetwork.orNull("172.17.0.1")
// 172.17.0.1
Rfc1918ClassBPrivateNetwork.orNull("80.34.200.60")

Resolved constraints

Rfc1918ClassBPrivateNetwork.constraints("172.17.0.1")
// [(true, Expected 172.17.0.1 to be an IPv4 address), (true, Expected 172.17.0.1 to match ^172\.(16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31)\..+)]
Rfc1918ClassBPrivateNetwork.constraints("80.34.200.60")
// [(true, Expected 80.34.200.60 to be an IPv4 address), (false, Expected 80.34.200.60 to match ^172\.(16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31)\..+)]
Rfc1918ClassBPrivateNetwork.isValid("172.17.0.1")
// true
Rfc1918ClassBPrivateNetwork.isValid("80.34.200.60")
// false

Folding validation

Rfc1918ClassBPrivateNetwork.fold("172.17.0.1", { "failed: $it" }, { "success: $it" })
// success: Rfc1918ClassBPrivateNetwork(value=172.17.0.1)
Rfc1918ClassBPrivateNetwork.fold("80.34.200.60", { "failed: $it" }, { "success: $it" })
// failed: [(false, Expected 80.34.200.60 to match ^172\.(16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31)\..+)]

Unsafe require

try { Rfc1918ClassBPrivateNetwork.require("80.34.200.60") } catch (e: IllegalArgumentException) { e.message }
// Expected 80.34.200.60 to match ^172\.(16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31)\..+
Rfc1918ClassBPrivateNetwork.require("172.17.0.1")
// 172.17.0.1

Types

Companion companion object Companion : Refined<String, Rfc1918ClassBPrivateNetwork>

Properties

value val value: String

Do you like Arrow?

Arrow Org
<