Foldable

trait Foldable[t: Type -> Type]Source

A trait for data structures that can be folded.

Signatures

def foldLeft(f: b -> (a -> b \ ef), s: b, t: t[a]): b \ ef 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 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 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 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] 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 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] 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 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] 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 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 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 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 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 with Foldable[t] Source

Applies f to each element in t.

def forEachM(f: a -> m[b] \ ef, t: t[a]): m[Unit] \ ef 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] with Foldable[t] Source

Optionally returns the first element of t.

Returns None if t is empty.

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

Returns true if and only if t is empty.

def join(sep: String, t: t[a]): String 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 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] with Foldable[t] Source

Optionally returns the last element of t.

Returns None if t is empty.

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

Returns the length of t, i.e. the number of times it can be folded over.

def maximum(t: t[a]): Option[a] 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] 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 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] 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] with Foldable[t] Source

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

Returns None if t is empty.

def reduceLeft(f: a -> (a -> a \ ef), t: t[a]): Option[a] \ ef 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 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 with Foldable[t] Source

Returns the sum of all elements in t.

def sumWith(f: a -> Int32 \ ef, t: t[a]): Int32 \ ef 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] 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 with Foldable[t] Source

Returns t as an array.

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

Returns t as a chain.

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

Returns t as a DelayList.

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

Returns t as a DelayMap

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

Returns t as an immutable list.

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

Returns t as a map.

def toMapWith(f: a -> b, s: t[a]): Map[a, b] 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 with Foldable[t] Source

Returns t as a MutDeque.

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

Returns t as a mutable list.

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

Returns t as a MutMap.

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

Returns the set s as a MutSet.

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

Optionally returns t as a non empty chain.

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

Optionally returns t as a non empty list.

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

Returns t as a set.

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

Returns t as a vector.

Module Definitions

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