arrow-refined-types / arrow.refinement.booleans / Equal

Equal

class Equal

Equal constrains Any? to be equal to an initial value

Safe nullable construction

import arrow.refinement.booleans.Equal

Equal.Value(1).orNull(1)
// Equal(value=1)
Equal.Value(1).orNull(0)

Resolved constraints

Equal.Value(1).constraints(1)
// [(true, 1 should be == 1)]
Equal.Value(1).constraints(0)
// [(false, 0 should be == 1)]
Equal.Value(1).isValid(1)
// true
Equal.Value(1).isValid(0)
// false

Folding validation

Equal.Value(1).fold(1, { "failed: $it" }, { "success: $it" })
// success: Equal(value=1)
Equal.Value(1).fold(0, { "failed: $it" }, { "success: $it" })
// failed: [(false, 0 should be == 1)]

Unsafe require

Equal.Value(1).require(1)
// 1
try { Equal.Value(1).require(0) } catch (e: IllegalArgumentException) { e.message }
// 0 should be == 1

Types

Value class Value<A> : Refined<A, Equal>

Properties

value val value: Any?

Do you like Arrow?

Arrow Org
<