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

Rfc2544BenchmarkNetwork

class Rfc2544BenchmarkNetwork

Rfc2544BenchmarkNetwork constrains String to be an IPv4 that StartsWith 198.18. or 198.19.

Safe nullable construction

import arrow.refinement.network.Rfc2544BenchmarkNetwork

Rfc2544BenchmarkNetwork.orNull("198.18.0.1")
// 198.18.0.1
Rfc2544BenchmarkNetwork.orNull("80.34.200.60")

Resolved constraints

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

Folding validation

Rfc2544BenchmarkNetwork.fold("198.18.0.1", { "failed: $it" }, { "success: $it" })
// success: Rfc2544BenchmarkNetwork(value=198.18.0.1)
Rfc2544BenchmarkNetwork.fold("80.34.200.60", { "failed: $it" }, { "success: $it" })
// failed: [(false, Expected 80.34.200.60 to start with 198.18.), (false, Expected 80.34.200.60 to start with 198.19.)]

Unsafe require

try { Rfc2544BenchmarkNetwork.require("80.34.200.60") } catch (e: IllegalArgumentException) { e.message }
// Expected 80.34.200.60 to start with 198.18., Expected 80.34.200.60 to start with 198.19.
Rfc2544BenchmarkNetwork.require("198.18.0.1")
// 198.18.0.1

Types

Companion companion object Companion : Refined<String, Rfc2544BenchmarkNetwork>

Properties

value val value: String

Do you like Arrow?

Arrow Org
<