Result

Definitions

def ap(r1: Result[e, t -> u \ ef], r2: Result[e, t]): Result[e, u] \ efSource

Applies the function in r1 to the value in r2.

def count(f: t -> Bool \ ef, r: Result[e, t]): Int32 \ efSource

Returns 1 if r is Ok(v) and the predicate f(v) evaluates to true. Otherwise returns 0.

def enumerator(rc: Region[r], r: Result[e, t]): Iterator[(Int32, t), r, r] \ rSource

Returns an iterator over r zipped with the indices of the elements.

def exists(f: t -> Bool \ ef, r: Result[e, t]): Bool \ efSource

Returns true if r is Ok(v) and the predicate f(v) evaluates to true. Otherwise returns false.

def find(f: t -> Bool, r: Result[e, t]): Option[t]Source

Returns Some(v) if r is Ok(v) and the predicate f(v) evaluates to true. Otherwise returns None.

The function f must be pure.

def flatMap(f: t1 -> Result[e, t2] \ ef, r: Result[e, t1]): Result[e, t2] \ efSource

Returns f(v) if r is Ok(v). Returns Err(w) if r is Err(w).

def flatten(r: Result[e, Result[e, t]]): Result[e, t]Source

Returns v if r is Ok(v). Returns Err(w) if r is Err(w).

def foldLeft(f: a -> (t -> a \ ef), z: a, r: Result[e, t]): a \ efSource

Returns f(z, v) if r is Ok(v). Otherwise returns z.

def foldLeftM(f: b -> (a -> Result[e, b] \ ef), s: b, l: List[a]): Result[e, b] \ efSource

Returns the result of applying f to a start value s and the elements in l going from left to right.

If at any step applying f fails (i.e. it produces a Err(e) value) the traversal of l is short-circuited and Err(e) is returned.

If f is successfully applied to all elements in l the result is of the form: Ok(f(...f(f(s, x1), x2)..., xn)).

def foldRight(f: t -> (a -> a \ ef), z: a, r: Result[e, t]): a \ efSource

Returns f(v, z) if r is Ok(v). Otherwise returns z.

def foldRightM(f: a -> (b -> Result[e, b] \ ef), s: b, l: List[a]): Result[e, b] \ efSource

Returns the result of applying f to a start value s and the elements in l going from right to left.

If at any step applying f fails (i.e. it produces a Err(e) value) the traversal of l is short-circuited and Err(e) is returned.

If f is successfully applied to all elements in l the result is of the form: Ok(f(x1, ...f(xn-1, f(xn, s))...)).

def foldRightWithCont(f: t -> ((Unit -> a \ ef) -> a \ ef), z: a, r: Result[e, t]): a \ efSource

Returns f(v, z) if r is Ok(v). Otherwise returns z.

A foldRightWithCont allows early termination by not calling the continuation.

def forAll(f: t -> Bool \ ef, r: Result[e, t]): Bool \ efSource

Returns true if r is Ok(v) and the predicate f(v) evaluates to true or if r is Err(w). Otherwise returns false.

def forEach(f: t -> Unit \ ef, r: Result[e, t]): Unit \ efSource

Applies f to v if r is Ok(v). Otherwise does nothing.

def getWithDefault(d: t, r: Result[e, t]): tSource

Returns v if r is Ok(v). Otherwise returns d.

def isErr(r: Result[e, t]): BoolSource

Returns true iff r is Err(w).

def isOk(r: Result[e, t]): BoolSource

Returns true iff r is Ok(v).

def iterator(rc: Region[r], r: Result[e, t]): Iterator[t, r, r] \ rSource

Returns an iterator over r with 1 element or an empty iterator if r is Err.

def map(f: t1 -> t2 \ ef, r: Result[e, t1]): Result[e, t2] \ efSource

Returns Ok(f(v)) if r is Ok(v). Returns Err(w) if r is Err(w).

def map10(f: t1 -> (t2 -> (t3 -> (t4 -> (t5 -> (t6 -> (t7 -> (t8 -> (t9 -> (t10 -> u \ ef))))))))), r1: Result[e, t1], r2: Result[e, t2], r3: Result[e, t3], r4: Result[e, t4], r5: Result[e, t5], r6: Result[e, t6], r7: Result[e, t7], r8: Result[e, t8], r9: Result[e, t9], r10: Result[e, t10]): Result[e, u] \ efSource

Applies the 10-ary function f to the values in r1, r2, ... r10.

Returns the first Err(e) value if any of r1, r2, ... r10 are Err(e).

def map2(f: t1 -> (t2 -> u \ ef), r1: Result[e, t1], r2: Result[e, t2]): Result[e, u] \ efSource

Applies the binary function f to the values in r1 and r2.

Returns the first Err(e) value if either of r1 and r2 are Err(e).

def map3(f: t1 -> (t2 -> (t3 -> u \ ef)), r1: Result[e, t1], r2: Result[e, t2], r3: Result[e, t3]): Result[e, u] \ efSource

Applies the ternary function f to the values in r1, r2 and r3.

Returns the first Err(e) value if any of r1, r2 and r3 are Err(e).

def map4(f: t1 -> (t2 -> (t3 -> (t4 -> u \ ef))), r1: Result[e, t1], r2: Result[e, t2], r3: Result[e, t3], r4: Result[e, t4]): Result[e, u] \ efSource

Applies the 4-ary function f to the values in r1, r2, r3 and r4.

Returns the first Err(e) value if any of r1, r2, r3 and r4 are Err(e).

def map5(f: t1 -> (t2 -> (t3 -> (t4 -> (t5 -> u \ ef)))), r1: Result[e, t1], r2: Result[e, t2], r3: Result[e, t3], r4: Result[e, t4], r5: Result[e, t5]): Result[e, u] \ efSource

Applies the 5-ary function f to the values in r1, r2, ... r5.

Returns the first Err(e) value if any of r1, r2, ... r5 are Err(e).

def map6(f: t1 -> (t2 -> (t3 -> (t4 -> (t5 -> (t6 -> u \ ef))))), r1: Result[e, t1], r2: Result[e, t2], r3: Result[e, t3], r4: Result[e, t4], r5: Result[e, t5], r6: Result[e, t6]): Result[e, u] \ efSource

Applies the 6-ary function f to the values in r1, r2, ... r6.

Returns the first Err(e) value if any of r1, r2, ... r6 are Err(e).

def map7(f: t1 -> (t2 -> (t3 -> (t4 -> (t5 -> (t6 -> (t7 -> u \ ef)))))), r1: Result[e, t1], r2: Result[e, t2], r3: Result[e, t3], r4: Result[e, t4], r5: Result[e, t5], r6: Result[e, t6], r7: Result[e, t7]): Result[e, u] \ efSource

Applies the 7-ary function f to the values in r1, r2, ... r7.

Returns the first Err(e) value if any of r1, r2, ... r7 are Err(e).

def map8(f: t1 -> (t2 -> (t3 -> (t4 -> (t5 -> (t6 -> (t7 -> (t8 -> u \ ef))))))), r1: Result[e, t1], r2: Result[e, t2], r3: Result[e, t3], r4: Result[e, t4], r5: Result[e, t5], r6: Result[e, t6], r7: Result[e, t7], r8: Result[e, t8]): Result[e, u] \ efSource

Applies the 8-ary function f to the values in r1, r2, ... r8.

Returns the first Err(e) value if any of r1, r2, ... r8 are Err(e).

def map9(f: t1 -> (t2 -> (t3 -> (t4 -> (t5 -> (t6 -> (t7 -> (t8 -> (t9 -> u \ ef)))))))), r1: Result[e, t1], r2: Result[e, t2], r3: Result[e, t3], r4: Result[e, t4], r5: Result[e, t5], r6: Result[e, t6], r7: Result[e, t7], r8: Result[e, t8], r9: Result[e, t9]): Result[e, u] \ efSource

Applies the 9-ary function f to the values in r1, r2, ... r9.

Returns the first Err(e) value if any of r1, r2, ... r9 are Err(e).

def mapErr(f: e1 -> e2 \ ef, r: Result[e1, t]): Result[e2, t] \ efSource

Returns Err(f(e)) if r is Err(e). Returns Ok(v) if r is Ok(v).

def replace(from: { from = t }, to: { to = t }, r: Result[e, t]): Result[e, t]Source

Returns Ok(to) if r is Ok(from). Otherwise returns r.

def sequence(l: List[Result[e, a]]): Result[e, List[a]]Source

Returns Ok(v1 :: v2 :: ... :: vn) if each of l_i is Ok(v_i). Otherwise returns the first Err encountered.

def sum(r: Result[e, Int32]): Int32Source

Returns v if r is Ok(v) else 0.

def sumWith(f: t -> Int32 \ ef, r: Result[e, t]): Int32 \ efSource

Returns f(v) if r is Ok(v) else 0.

def toList(r: Result[e, t]): List[t]Source

Returns a one-element list of the value v if r is Ok(v). Otherwise returns the empty list.

def toMap(r: Result[e, (k, v)]): Map[k, v]Source

Returns a singleton map with the mapping k -> v if o is Ok((k, v)). Otherwise returns the empty map.

def toMapWith(f: a -> b, s: Result[a, a]): Map[a, b]Source

Returns a map with elements of s as keys and f applied as values.

def toOption(r: Result[e, t]): Option[t]Source

Returns Some(v) if r is Ok(v). Otherwise returns None.

def toSet(r: Result[e, t]): Set[t]Source

Returns a one-element set of the value v if r is Ok(v). Otherwise returns the empty set.

def toValidation(r: Result[e, t]): Validation[e, t]Source

Returns a Success(v) if r is Ok(v). Otherwise returns a Failure(Nec.singleton(t)) if r is Err(t).

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

Returns Some(v1 :: v2 :: ... v :: vn) if each of f(l_i) is Ok(v_i). Otherwise returns the first Err encountered.

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

Returns Ok() if each of f(l_i) is Ok(_). Otherwise returns None.

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 tryCatch(f: Unit -> a \ ef): Result[String, a] \ efSource

Returns Ok(x) if f was invoked without throwing an exception.

If f throws a Java Exception, Err(e) is returned where e is the error message.

def withDefault(default: { default = Result[e2, t] }, r: Result[e1, t]): Result[e2, t]Source

Returns Ok(v) if r is Ok(v). Otherwise returns default.