flix

0.54.0

Option

enum Option[t: Type] with Eq, Order, ToString, SendableSource
case Nonecase Some(t)

The Option type.

An option represents an optional value. The constructor None represents an absent value, whereas the constructor Some(v) represents the value v.

Instances

instance Applicative[Option]Source
instance CommutativeMonoid[Option[a]] with CommutativeMonoid[a]Source
instance Eq[Option[t]] with Eq[t]Source
instance Filterable[Option]Source
instance Foldable[Option]Source
instance Functor[Option]Source
instance Hash[Option[a]] with Hash[a]Source
instance Iterable[Option[a]]Source
instance JoinLattice[Option[t]] with JoinLattice[t]Source
instance LowerBound[Option[t]]Source
instance MeetLattice[Option[t]] with MeetLattice[t]Source
instance Monad[Option]Source
instance MonadZero[Option]Source
instance MonadZip[Option]Source
instance Monoid[Option[a]] with Monoid[a]Source
instance Order[Option[t]] with Order[t]Source
instance PartialOrder[Option[t]] with PartialOrder[t]Source
instance SemiGroup[Option[a]] with SemiGroup[a]Source
instance Sendable[Option[t]] with Sendable[t]Source
instance ToString[Option[t]] with ToString[t]Source
instance Traversable[Option]Source
instance UnorderedFoldable[Option]Source
instance Witherable[Option]Source

Definitions

def ap(f: Option[a -> b \ ef], x: Option[a]): Option[b] \ ef Source

If both arguments are Some, return a Some containing the result of applying the function inside f to the value inside x. Otherwise return None.

def count(f: a -> Bool \ ef, o: Option[a]): Int32 \ ef Source

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

def empty(): Option[a] Source

Returns the empty option variant None.

def enumerator(rc: Region[r], o: Option[a]): Iterator[(Int32, a), r, r] \ r Source

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

def exists(f: a -> Bool \ ef, o: Option[a]): Bool \ ef Source

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

def filter(f: a -> Bool \ ef, o: Option[a]): Option[a] \ ef Source

Returns o if o is Some(v) and the predicate f(v) is true. Otherwise returns None.

def find(f: a -> Bool, o: Option[a]): Option[a] Source

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

The function f must be pure.

def flatMap(f: a -> Option[b] \ ef, o: Option[a]): Option[b] \ ef Source

Returns f(v) if o is Some(v). Otherwise returns None.

def flatten(o: Option[Option[a]]): Option[a] Source

Returns v if o is Some(v). Otherwise returns None.

def fold(o: Option[a]): a with Monoid[a] Source

Returns the result of applying combine to all the elements in o, using empty as the initial value.

def foldLeft(f: b -> (a -> b \ ef), z: b, o: Option[a]): b \ ef Source

Returns f(z, v) if o is Some(v). Otherwise returns z.

def foldLeftM(f: b -> (a -> Option[b] \ ef), s: b, l: List[a]): Option[b] \ ef Source

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 None value) the traversal of l is short-circuited and None is returned.

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

def foldMap(f: a -> b \ ef, o: Option[a]): b \ ef with Monoid[b] Source

Returns the result of mapping each element and combining the results.

def foldRight(f: a -> (b -> b \ ef), o: Option[a], z: b): b \ ef Source

Returns f(v, z) if o is Some(v). Otherwise returns z.

def foldRightM(f: a -> (b -> Option[b] \ ef), s: b, l: List[a]): Option[b] \ ef Source

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 None value) the traversal of l is short-circuited and None is returned.

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

def foldRightWithCont(f: a -> ((Unit -> b \ ef) -> b \ ef), o: Option[a], z: b): b \ ef Source

Returns f(v, z) if o is Some(v). Otherwise returns z.

A foldRightWithCont allows early termination by not calling the continuation.

def forAll(f: a -> Bool \ ef, o: Option[a]): Bool \ ef Source

Returns true if o is Some(v) and the predicate f(v) evaluates to true or if o is None.

Otherwise returns false.

def forEach(f: a -> Unit \ ef, o: Option[a]): Unit \ ef Source

Applies f to v if o is Some(v). Otherwise does nothing.

def getWithDefault(d: a, o: Option[a]): a Source

Returns v if o is Some(v). Otherwise returns d.

def isEmpty(o: Option[a]): Bool Source

Returns true iff o is None.

def iterator(rc: Region[r], o: Option[a]): Iterator[a, r, r] \ r Source

Returns an iterator over o with 1 element or an empty iterator if o is None.

def map(f: a -> b \ ef, o: Option[a]): Option[b] \ ef Source

Returns Some(f(v)) if o is Some(v). Otherwise returns None.

def map10(f: t1 -> (t2 -> (t3 -> (t4 -> (t5 -> (t6 -> (t7 -> (t8 -> (t9 -> (t10 -> u \ ef))))))))), o1: Option[t1], o2: Option[t2], o3: Option[t3], o4: Option[t4], o5: Option[t5], o6: Option[t6], o7: Option[t7], o8: Option[t8], o9: Option[t9], o10: Option[t10]): Option[u] \ ef Source

Applies the 10-ary function f to the values in o1, o2, ... o10.

Returns None if any of o1, o2, ... o10 are None.

def map2(f: t1 -> (t2 -> u \ ef), o1: Option[t1], o2: Option[t2]): Option[u] \ ef Source

Applies the binary function f to the values in o1 and o2.

Returns None if either o1 or o2 are None.

def map3(f: t1 -> (t2 -> (t3 -> u \ ef)), o1: Option[t1], o2: Option[t2], o3: Option[t3]): Option[u] \ ef Source

Applies the ternary function f to the values in o1, o2 and o3.

Returns None if any of o1, o2 and o3 are None.

def map4(f: t1 -> (t2 -> (t3 -> (t4 -> u \ ef))), o1: Option[t1], o2: Option[t2], o3: Option[t3], o4: Option[t4]): Option[u] \ ef Source

Applies the 4-ary function f to the values in o1, o2, o3 and o4.

Returns None if any of o1, o2, o3 and o4 are None.

def map5(f: t1 -> (t2 -> (t3 -> (t4 -> (t5 -> u \ ef)))), o1: Option[t1], o2: Option[t2], o3: Option[t3], o4: Option[t4], o5: Option[t5]): Option[u] \ ef Source

Applies the 5-ary function f to the values in o1, o2, ... o5.

Returns None if any of o1, o2, ... o5 are None.

def map6(f: t1 -> (t2 -> (t3 -> (t4 -> (t5 -> (t6 -> u \ ef))))), o1: Option[t1], o2: Option[t2], o3: Option[t3], o4: Option[t4], o5: Option[t5], o6: Option[t6]): Option[u] \ ef Source

Applies the 6-ary function f to the values in o1, o2, ... o6.

Returns None if any of o1, o2, ... o6 are None.

def map7(f: t1 -> (t2 -> (t3 -> (t4 -> (t5 -> (t6 -> (t7 -> u \ ef)))))), o1: Option[t1], o2: Option[t2], o3: Option[t3], o4: Option[t4], o5: Option[t5], o6: Option[t6], o7: Option[t7]): Option[u] \ ef Source

Applies the 7-ary function f to the values in o1, o2, ... o7.

Returns None if any of o1, o2, ... o7 are None.

def map8(f: t1 -> (t2 -> (t3 -> (t4 -> (t5 -> (t6 -> (t7 -> (t8 -> u \ ef))))))), o1: Option[t1], o2: Option[t2], o3: Option[t3], o4: Option[t4], o5: Option[t5], o6: Option[t6], o7: Option[t7], o8: Option[t8]): Option[u] \ ef Source

Applies the 8-ary function f to the values in o1, o2, ... o8.

Returns None if any of o1, o2, ... o8 are None.

def map9(f: t1 -> (t2 -> (t3 -> (t4 -> (t5 -> (t6 -> (t7 -> (t8 -> (t9 -> u \ ef)))))))), o1: Option[t1], o2: Option[t2], o3: Option[t3], o4: Option[t4], o5: Option[t5], o6: Option[t6], o7: Option[t7], o8: Option[t8], o9: Option[t9]): Option[u] \ ef Source

Applies the 9-ary function f to the values in o1, o2, ... o9.

Returns None if any of o1, o2, ... o9 are None.

def nonEmpty(o: Option[a]): Bool Source

Returns true iff o is Some.

def point(x: a): Option[a] Source

Returns Some(x).

def replace(src: { src = a }, dst: { dst = a }, o: Option[a]): Option[a] with Eq[a] Source

Returns Some(dst) if o is Some(src). Otherwise returns o.

def sequence(l: List[Option[a]]): Option[List[a]] Source

Returns Some(v1 :: v2 :: ... :: vn) if each of xs_i is Some(v_i). Otherwise returns None.

def sum(o: Option[Int32]): Int32 Source

Returns v if o is Some(v) else 0.

def sumWith(f: a -> Int32 \ ef, o: Option[a]): Int32 \ ef Source

Returns f(v) if o is Some(v) else 0.

def toErr(d: t, o: Option[e]): Result[e, t] Source

Returns the Option value Err(e) if o is Some(e). Otherwise returns Ok(d).

def toFailure(d: t, o: Option[e]): Validation[e, t] Source

Returns e into Validation's Failure if o is Some(e). Otherwise returns Success(d).

def toList(o: Option[a]): List[a] Source

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

def toMap(o: Option[(k, v)]): Map[k, v] with Order[k] Source

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

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

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

def toOk(e: e, o: Option[t]): Result[e, t] Source

Returns the Option value Ok(v) if o is Some(v). Otherwise returns Err(e).

def toSet(o: Option[a]): Set[a] with Order[a] Source

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

def toSuccess(e: e, o: Option[t]): Validation[e, t] Source

Returns the Validation value Success(v) if o is Some(v). Otherwise lifts e into Validation's Failure.

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

Returns Some(v1 :: v2 :: ... v :: vn) if each of f(l_i) is Some(v_i). Otherwise returns None.

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

Returns Some() if each of f(l_i) is Some(_). 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 unzip(o: Option[(a, b)]): (Option[a], Option[b]) Source

Returns (Some(v1), Some(v2)) if o is Some((v1, v2)). Otherwise returns (None, None).

def withDefault(default: { default = Option[a] }, o: Option[a]): Option[a] Source

Returns o if it is Some(v). Otherwise returns default.

def zip(o1: Option[a], o2: Option[b]): Option[(a, b)] Source

Returns Some((v1, v2)) if o1 is Some(v1) and o2 is Some(v2). Otherwise returns None.