Validation

@MustUse
enum Validation[e: Type, t: Type] with Eq, Order, ToString, SendableSource
case Success(t)case Failure(Nec[e])

The Validation type.

Instances

instance Applicative[Validation[e]]Source
instance Eq[Validation[e, t]] with Eq[e], Eq[t]Source
instance Functor[Validation[e]]Source
instance Hash[Validation[e, t]] with Hash[e], Hash[t]Source
instance Monoid[Validation[e, t]] with Monoid[t]Source
instance Order[Validation[e, t]] with Order[e], Order[t]Source
instance SemiGroup[Validation[e, t]] with SemiGroup[t]Source
instance Sendable[Validation[e, t]] with Sendable[e], Sendable[t]Source
instance ToString[Validation[e, t]] with ToString[e], ToString[t]Source

Definitions

def ap(v1: Validation[e, t -> u \ ef], v2: Validation[e, t]): Validation[e, u] \ ef Source

Applies the function in v1 to the value in v2.

def exists(f: t -> Bool \ ef, v: Validation[e, t]): Bool \ ef Source

Returns true if and only if v is Success(t) and f(t) is true.

Returns false if v is Failure.

def forAll(f: t -> Bool \ ef, v: Validation[e, t]): Bool \ ef Source

Returns true if v is Success(t) and f(t) is true or if v is Failure.

def getWithDefault(d: t, v: Validation[e, t]): t Source

Returns t if v is Success(t). Otherwise returns d.

def map(f: t -> u \ ef, v: Validation[e, t]): Validation[e, u] \ ef Source

Returns Success(f(v)) if o is Success(v). Otherwise returns v.

def map10(f: t1 -> (t2 -> (t3 -> (t4 -> (t5 -> (t6 -> (t7 -> (t8 -> (t9 -> (t10 -> u \ ef))))))))), v1: Validation[e, t1], v2: Validation[e, t2], v3: Validation[e, t3], v4: Validation[e, t4], v5: Validation[e, t5], v6: Validation[e, t6], v7: Validation[e, t7], v8: Validation[e, t8], v9: Validation[e, t9], v10: Validation[e, t10]): Validation[e, u] \ ef Source

Applies the 10-ary function f to the values in v1, v2, ... v10.

Returns the concatenation of all the failures as Failure(xs) if any of v1, v2, ... v10 are Failure(xs1).

def map2(f: t1 -> (t2 -> u \ ef), v1: Validation[e, t1], v2: Validation[e, t2]): Validation[e, u] \ ef Source

Applies the binary function f to the values in v1 and v2.

Returns the concatenation of all the failures as Failure(xs) if either or both of v1 or v2 are Failure(xs1).

def map3(f: t1 -> (t2 -> (t3 -> u \ ef)), v1: Validation[e, t1], v2: Validation[e, t2], v3: Validation[e, t3]): Validation[e, u] \ ef Source

Applies the ternary function f to the values in v1, v2 and v3.

Returns the concatenation of all the failures as Failure(xs) if any of v1, v2 and v3 are Failure(xs1).

def map4(f: t1 -> (t2 -> (t3 -> (t4 -> u \ ef))), v1: Validation[e, t1], v2: Validation[e, t2], v3: Validation[e, t3], v4: Validation[e, t4]): Validation[e, u] \ ef Source

Applies the 4-ary function f to the values in v1, v2, v3 and v4.

Returns the concatenation of all the failures as Failure(xs) if any of v1, v2, v3 and v4 are Failure(xs1).

def map5(f: t1 -> (t2 -> (t3 -> (t4 -> (t5 -> u \ ef)))), v1: Validation[e, t1], v2: Validation[e, t2], v3: Validation[e, t3], v4: Validation[e, t4], v5: Validation[e, t5]): Validation[e, u] \ ef Source

Applies the 5-ary function f to the values in v1, v2, ... v5.

Returns the concatenation of all the failures as Failure(xs) if any of v1, v2, ... v5 are Failure(xs1).

def map6(f: t1 -> (t2 -> (t3 -> (t4 -> (t5 -> (t6 -> u \ ef))))), v1: Validation[e, t1], v2: Validation[e, t2], v3: Validation[e, t3], v4: Validation[e, t4], v5: Validation[e, t5], v6: Validation[e, t6]): Validation[e, u] \ ef Source

Applies the 6-ary function f to the values in v1, v2, ... v6.

Returns the concatenation of all the failures as Failure(xs) if any of v1, v2, ... v6 are Failure(xs1).

def map7(f: t1 -> (t2 -> (t3 -> (t4 -> (t5 -> (t6 -> (t7 -> u \ ef)))))), v1: Validation[e, t1], v2: Validation[e, t2], v3: Validation[e, t3], v4: Validation[e, t4], v5: Validation[e, t5], v6: Validation[e, t6], v7: Validation[e, t7]): Validation[e, u] \ ef Source

Applies the 7-ary function f to the values in v1, v2, ... v7.

Returns the concatenation of all the failures as Failure(xs) if any of v1, v2, ... v7 are Failure(xs1).

def map8(f: t1 -> (t2 -> (t3 -> (t4 -> (t5 -> (t6 -> (t7 -> (t8 -> u \ ef))))))), v1: Validation[e, t1], v2: Validation[e, t2], v3: Validation[e, t3], v4: Validation[e, t4], v5: Validation[e, t5], v6: Validation[e, t6], v7: Validation[e, t7], v8: Validation[e, t8]): Validation[e, u] \ ef Source

Applies the 8-ary function f to the values in v1, v2, ... v8.

Returns the concatenation of all the failures as Failure(xs) if any of v1, v2, ... v8 are Failure(xs1).

def map9(f: t1 -> (t2 -> (t3 -> (t4 -> (t5 -> (t6 -> (t7 -> (t8 -> (t9 -> u \ ef)))))))), v1: Validation[e, t1], v2: Validation[e, t2], v3: Validation[e, t3], v4: Validation[e, t4], v5: Validation[e, t5], v6: Validation[e, t6], v7: Validation[e, t7], v8: Validation[e, t8], v9: Validation[e, t9]): Validation[e, u] \ ef Source

Applies the 9-ary function f to the values in v1, v2, ... v9.

Returns the concatenation of all the failures as Failure(xs) if any of v1, v2, ... v9 are Failure(xs1).

def product(fa: Validation[e, t1], fb: Validation[e, t2]): Validation[e, (t1, t2)] Source

Chain two functions, returns the product of their results.

def product3(fa: Validation[e, t1], fb: Validation[e, t2], fc: Validation[e, t3]): Validation[e, (t1, t2, t3)] Source

Chain three functions, returns the product of their results.

def product4(fa: Validation[e, t1], fb: Validation[e, t2], fc: Validation[e, t3], fd: Validation[e, t4]): Validation[e, (t1, t2, t3, t4)] Source

Chain four functions, returns the product of their results.

def product5(fa: Validation[e, t1], fb: Validation[e, t2], fc: Validation[e, t3], fd: Validation[e, t4], fe: Validation[e, t5]): Validation[e, (t1, t2, t3, t4, t5)] Source

Chain five functions, returns the product of their results.

def sequence(l: List[Validation[e, t]]): Validation[e, List[t]] Source

Returns Success(v1 :: v2 :: ... :: vn) if each of l_i is Success(v_i).

Otherwise returns Failure(e1 :: ... :: en) with all of the failures concatenated.

def toList(v: Validation[e, t]): List[t] Source

Converts a Validation to a List.

Returns t :: Nil if v is Success(v). Returns Nil if v is Failure(e).

def toOption(v: Validation[e, t]): Option[t] Source

Converts a Validation to an Option.

Returns Some(t) if v is Success(t). Returns None otherwise.

def toResult(v: Validation[e, t]): Result[Nec[e], t] Source

Converts a Validation to a Result.

Returns Ok(t) if v is Success(t). Returns Err(e) if v is Failure(e).

def traverse(f: a -> Validation[e, b] \ ef, l: List[a]): Validation[e, List[b]] \ ef Source

Returns Success(v1 :: v2 :: ... v :: vn) if each of f(l_i) is Success(v_i).

Otherwise returns Failure(e1 :: ... :: en) with all of the failures concatenated.

def traverseX(f: a -> Validation[e, b] \ ef, l: List[a]): Validation[e, Unit] \ ef Source

Returns Success() if each of f(l_i) is Success(_).

Otherwise returns Failure(e1 :: ... :: en) with all of the failures concatenated.

This function is the "forgetful" version of traverse, use it when the you want the effect of applying f to each element but do not care about collecting the results.

def withDefault(default: { default = Validation[e, t] }, v: Validation[e, t]): Validation[e, t] Source

Returns v if it is Success(v). Otherwise returns default.