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

URL

class URL

JVM only

URL constrains String to be validated by java.net.URL

Safe nullable construction

import arrow.refinement.network.URL

URL.orNull("https://arrow-kt.io/")
// https://arrow-kt.io/
URL.orNull("not-url")

Resolved constraints

URL.constraints("https://arrow-kt.io/")
// [(true, Expected https://arrow-kt.io/ to be a valid URL)]
URL.constraints("not-url")
// [(false, Expected not-url to be a valid URL)]
URL.isValid("https://arrow-kt.io/")
// true
URL.isValid("not-url")
// false

Folding validation

URL.fold("https://arrow-kt.io/", { "failed: $it" }, { "success: $it" })
// success: URL(value=https://arrow-kt.io/)
URL.fold("not-url", { "failed: $it" }, { "success: $it" })
// failed: [(false, Expected not-url to be a valid URL)]

Unsafe require

URL.require("https://arrow-kt.io/")
// https://arrow-kt.io/
try { URL.require("not-url") } catch (e: IllegalArgumentException) { e.message }
// Expected not-url to be a valid URL

Types

Companion companion object Companion : Refined<String, URL>

Properties

value val value: String

Do you like Arrow?

Arrow Org
<