arrow-refined-types / arrow.refinement.strings / UUID

UUID

class UUID

JVM only

UUID constrains String to be a valid java.util.UUID

Safe nullable construction

import arrow.refinement.strings.UUID

UUID.orNull("123e4567-e89b-12d3-a456-556642440000")
// 123e4567-e89b-12d3-a456-556642440000
UUID.orNull("abc")

Resolved constraints

UUID.constraints("123e4567-e89b-12d3-a456-556642440000")
// [(true, Expected 123e4567-e89b-12d3-a456-556642440000 to be a valid UUID)]
UUID.constraints("abc")
// [(false, Expected abc to be a valid UUID)]
UUID.isValid("123e4567-e89b-12d3-a456-556642440000")
// true
UUID.isValid("abc")
// false

Folding validation

UUID.fold("123e4567-e89b-12d3-a456-556642440000", { "failed: $it" }, { "success: $it" })
// success: UUID(value=123e4567-e89b-12d3-a456-556642440000)
UUID.fold("abc", { "failed: $it" }, { "success: $it" })
// failed: [(false, Expected abc to be a valid UUID)]

Unsafe require

UUID.require("123e4567-e89b-12d3-a456-556642440000")
// 123e4567-e89b-12d3-a456-556642440000
try { UUID.require("abc") } catch (e: IllegalArgumentException) { e.message }
// Expected abc to be a valid UUID

Types

Companion companion object Companion : Refined<String, UUID>

Properties

value val value: String

Do you like Arrow?

Arrow Org
<