flix

0.55.0

Foldable

trait Foldable[t: Type -> Type]Source

A trait for data structures that can be folded.

Associated Types

type Aef: EffSource

The associated effect of the Foldable which represents the effect of accessing its elements.

Instances

instance Foldable[Chain]Source
instance Foldable[DelayList]Source
instance Foldable[DelayMap[k]]Source
instance Foldable[Identity]Source
instance Foldable[List]Source
instance Foldable[Map[k]]Source
instance Foldable[MultiMap[k]]Source
instance Foldable[Nec]Source
instance Foldable[Nel]Source
instance Foldable[Option]Source
instance Foldable[RedBlackTree[k]]Source
instance Foldable[Set]Source
instance Foldable[Vector]Source

Signatures

def foldLeft(f: b -> (a -> b \ ef), s: b, t: t[a]): b \ ef + Aef[t] with Foldable[t] Source

Left-associative fold of a structure. Applies f to a start value s and all elements in t going from left to right.

def foldRight(f: a -> (b -> b \ ef), s: b, t: t[a]): b \ ef + Aef[t] with Foldable[t] Source

Right-associative fold of a structure. Applies f to a start value s and all elements in t going from right to left.

def foldRightWithCont(f: a -> ((Unit -> b \ ef) -> b \ ef), s: b, t: t[a]): b \ ef + Aef[t] with Foldable[t] Source

Right-associative fold of a structure. Applies f to a start value s and all elements in t going from right to left.

A foldRightWithCont allows early termination by not calling the continuation.

Trait Definitions

def count(f: a -> Bool \ ef, t: t[a]): Int32 \ ef + Aef[t] with Foldable[t] Source

Returns the number of elements in t that satisfy the predicate f.

def dropWhile(f: a -> Bool, t: t[a]): List[a] \ Aef[t] with Foldable[t] Source

Returns t without the longest prefix that satisfies the predicate f.

Returns an immutable list.

def exists(f: a -> Bool \ ef, t: t[a]): Bool \ ef + Aef[t] with Foldable[t] Source

Returns true if and only if at least one element in t satisfies the predicate f.

Returns false if t is empty.

def filter(f: a -> Bool, t: t[a]): List[a] \ Aef[t] with Foldable[t] Source

Returns an immutable list of all the elements in t that satisfy the predicate f.

def findLeft(f: a -> Bool \ ef, t: t[a]): Option[a] \ ef + Aef[t] with Foldable[t] Source

Optionally returns the first element of t that satisfies the predicate f when searching from left to right.

Returns None if t is empty.

def findRight(f: a -> Bool, t: t[a]): Option[a] \ Aef[t] with Foldable[t] Source

Optionally returns the first element of t that satisfies the predicate f when searching from right to left.

Returns None if t is empty.

def foldLeftM(f: b -> (a -> m[b] \ ef), s: b, t: t[a]): m[b] \ ef + Aef[t] with Foldable[t], Monad[m] Source

A monadic version of foldLeft.

Applies the monadic f to a start value s and all elements in t going from left to right.

def foldMap(f: a -> b \ ef, t: t[a]): b \ ef + Aef[t] with Foldable[t], Monoid[b] Source

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

def foldRightM(f: a -> (b -> m[b] \ ef), s: b, t: t[a]): m[b] \ ef + Aef[t] with Foldable[t], Monad[m] Source

A monadic version of foldRight.

Applies the monadic f to a start value s and all elements in t going from right to left.

def forAll(f: a -> Bool \ ef, t: t[a]): Bool \ ef + Aef[t] with Foldable[t] Source

Returns true if and only if all elements in t satisfy the predicate f.

Returns true if t is empty.

def forEach(f: a -> Unit \ ef, t: t[a]): Unit \ ef + Aef[t] with Foldable[t] Source

Applies f to each element in t.

def forEachM(f: a -> m[b] \ ef, t: t[a]): m[Unit] \ ef + Aef[t] with Foldable[t], Monad[m] Source

A monadic version of forEach.

Apply f to every value in t. f is applied for its monadic effect, the answer it produces is discarded.

def head(t: t[a]): Option[a] \ Aef[t] with Foldable[t] Source

Optionally returns the first element of t.

Returns None if t is empty.

def isEmpty(t: t[a]): Bool \ Aef[t] with Foldable[t] Source

Returns true if and only if t is empty.

def join(sep: String, t: t[a]): String \ Aef[t] with Foldable[t], ToString[a] Source

Returns the concatenation of the string representation of each element in t with sep inserted between each element.

def joinWith(f: a -> String \ ef, sep: String, t: t[a]): String \ ef + Aef[t] with Foldable[t] Source

Returns the concatenation of the string representation of each element in t according to f with sep inserted between each element.

def last(t: t[a]): Option[a] \ Aef[t] with Foldable[t] Source

Optionally returns the last element of t.

Returns None if t is empty.

def length(t: t[a]): Int32 \ Aef[t] with Foldable[t] Source

Returns the number of elements in t.

def maximum(t: t[a]): Option[a] \ Aef[t] with Foldable[t], Order[a] Source

Optionally finds the largest element of t according to the Order on a.

Returns None if t is empty.

def maximumBy(cmp: a -> (a -> Comparison), t: t[a]): Option[a] \ Aef[t] with Foldable[t] Source

Optionally finds the largest element of t according to the given comparator cmp.

Returns None if t is empty.

def memberOf(x: a, t: t[a]): Bool \ Aef[t] with Foldable[t], Eq[a] Source

Returns true if and only if the element x is in t.

def minimum(t: t[a]): Option[a] \ Aef[t] with Foldable[t], Order[a] Source

Optionally finds the smallest element of t according to the Order on a.

Returns None if t is empty.

def minimumBy(cmp: a -> (a -> Comparison), t: t[a]): Option[a] \ Aef[t] with Foldable[t] Source

Optionally finds the smallest element of t according to the given comparator cmp.

Returns None if t is empty.

def nonEmpty(t: t[a]): Bool \ Aef[t] with Foldable[t] Source

Returns true if and only if t is non-empty.

def reduceLeft(f: a -> (a -> a \ ef), t: t[a]): Option[a] \ ef + Aef[t] with Foldable[t] Source

Optionally applies f to all elements in t going from left to right until a single value is obtained.

Returns None if t is empty.

def reduceRight(f: a -> (a -> a \ ef), t: t[a]): Option[a] \ ef + Aef[t] with Foldable[t] Source

Optionally applies f to all elements in t going from right to left until a single value is obtained.

Returns None if t is empty.

def sum(t: t[Int32]): Int32 \ Aef[t] with Foldable[t] Source

Returns the sum of all elements in t.

def sumWith(f: a -> Int32 \ ef, t: t[a]): Int32 \ ef + Aef[t] with Foldable[t] Source

Returns the sum of all elements in t according to the function f.

def takeWhile(f: a -> Bool, t: t[a]): List[a] \ Aef[t] with Foldable[t] Source

Returns the longest prefix of t that satisfies the predicate f.

Returns an immutable list.

def toArray(rc: Region[r], t: t[a]): Array[a, r] \ r + Aef[t] with Foldable[t] Source

Returns t as an array.

def toChain(t: t[a]): Chain[a] \ Aef[t] with Foldable[t] Source

Returns t as a chain.

def toDelayList(t: t[a]): DelayList[a] \ Aef[t] with Foldable[t] Source

Returns t as a DelayList.

def toDelayMap(t: t[(k, v)]): DelayMap[k, v] \ Aef[t] with Foldable[t], Order[k] Source

Returns t as a DelayMap

def toList(t: t[a]): List[a] \ Aef[t] with Foldable[t] Source

Returns t as an immutable list.

def toMap(t: t[(k, v)]): Map[k, v] \ Aef[t] with Foldable[t], Order[k] Source

Returns t as a map.

def toMapWith(f: a -> b, s: t[a]): Map[a, b] \ Aef[t] with Foldable[t], Order[a] Source

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

def toMutDeque(rc: Region[r], t: t[a]): MutDeque[a, r] \ r + Aef[t] with Foldable[t] Source

Returns t as a MutDeque.

def toMutList(rc: Region[r], t: t[a]): MutList[a, r] \ r + Aef[t] with Foldable[t] Source

Returns t as a mutable list.

def toMutMap(rc: Region[r], t: t[(k, v)]): MutMap[k, v, r] \ r + Aef[t] with Foldable[t], Order[k] Source

Returns t as a MutMap.

def toMutSet(rc: Region[r], t: t[a]): MutSet[a, r] \ r + Aef[t] with Foldable[t], Order[a] Source

Returns the set s as a MutSet.

def toNec(t: t[a]): Option[Nec[a]] \ Aef[t] with Foldable[t] Source

Optionally returns t as a non empty chain.

def toNel(t: t[a]): Option[Nel[a]] \ Aef[t] with Foldable[t] Source

Optionally returns t as a non empty list.

def toSet(t: t[a]): Set[a] \ Aef[t] with Foldable[t], Order[a] Source

Returns t as a set.

def toVector(t: t[a]): Vector[a] \ Aef[t] with Foldable[t] Source

Returns t as a vector.

Module Definitions

def fold(t: t[a]): a \ Aef[t] with Foldable[t], Monoid[a] Source

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

def size(t: t[a]): Int32 \ Aef[t] with Foldable[t] Source

Returns the number of elements in t.