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

Not

class Not<A, B> : Refined<A, B>

Boolean negation of a predicate. !predicate

Safe nullable construction

import arrow.refinement.booleans.Equal
import arrow.refinement.booleans.Not

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

Resolved constraints

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

Folding validation

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

Unsafe require

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

See Also

arrow.refinement.Refined.not

Constructors

<init> Boolean negation of a predicate. !predicateNot(predicate: Refined<A, B>, defaultMsg: (A) -> String? = { null })

Extension Functions

toEither fun <V, R> Refined<V, R>.toEither(value: V): Either<String, R>
toValidated fun <V, R> Refined<V, R>.toValidated(value: V): Validated<String, R>
toValidatedNel fun <V, R> Refined<V, R>.toValidatedNel(value: V): ValidatedNel<String, R>

Do you like Arrow?

Arrow Org
<