arrow-core-data / arrow.typeclasses / Foldable

Foldable

interface Foldable<F>

Data structures that can be folded to a summary value.

Foldable is implemented in terms of two basic methods:

  • fa.foldLeft(init, f) eagerly folds fa from left-to-right.
  • fa.foldRight(init, f) lazily folds fa from right-to-left.

Beyond these it provides many other useful methods related to folding over F values.

Functions

combineAll Alias for fold.open fun <A> Kind<F, A>.combineAll(MN: Monoid<A>): A
exists Check whether at least one element satisfies the predicate.open fun <A> Kind<F, A>.exists(p: (A) -> Boolean): Boolean
find Find the first element matching the predicate, if one exists.open fun <A> Kind<F, A>.find(f: (A) -> Boolean): Option<A>
firstOption Get the first element of the foldable or noneopen fun <A> Kind<F, A>.firstOption(): Option<A>
Get the first element of the foldable or none if empty or the predicate does not matchopen fun <A> Kind<F, A>.firstOption(predicate: (A) -> Boolean): Option<A>
fold Fold implemented using the given Monoid instance.open fun <A> Kind<F, A>.fold(MN: Monoid<A>): A
foldLeft Left associative fold on F using the provided function.abstract fun <A, B> Kind<F, A>.foldLeft(b: B, f: (B, A) -> B): B
foldM Left associative monadic folding on F.open fun <G, A, B> Kind<F, A>.foldM(M: Monad<G>, z: B, f: (B, A) -> Kind<G, B>): Kind<G, B>
foldMap Fold implemented by mapping A values into B and then combining them using the given Monoid instance.open fun <A, B> Kind<F, A>.foldMap(MN: Monoid<B>, f: (A) -> B): B
foldMapM Monadic folding on F by mapping A values to G, combining the B values using the given Monoid instance.open fun <G, A, B, MA : Monad<G>, MO : Monoid<B>> Kind<F, A>.foldMapM(ma: MA, mo: MO, f: (A) -> Kind<G, B>): Kind<G, B>
foldRight Right associative lazy fold on F using the provided function.abstract fun <A, B> Kind<F, A>.foldRight(lb: Eval<B>, f: (A, Eval<B>) -> Eval<B>): Eval<B>
forAll Check whether all elements satisfy the predicate.open fun <A> Kind<F, A>.forAll(p: (A) -> Boolean): Boolean
get Get the element at the index of the Foldable.open fun <A> Kind<F, A>.get(idx: Long): Option<A>
isEmpty Returns true if there are no elements. Otherwise false.open fun <A> Kind<F, A>.isEmpty(): Boolean
nonEmpty open fun <A> Kind<F, A>.nonEmpty(): Boolean
orEmpty open fun <A> orEmpty(AF: Applicative<F>, MA: Monoid<A>): Kind<F, A>
reduceLeftOption Reduce the elements of this structure down to a single value by applying the provided aggregation function in a left-associative manner.open fun <A> Kind<F, A>.reduceLeftOption(f: (A, A) -> A): Option<A>
reduceLeftToOption open fun <A, B> Kind<F, A>.reduceLeftToOption(f: (A) -> B, g: (B, A) -> B): Option<B>
reduceRightOption Reduce the elements of this structure down to a single value by applying the provided aggregation function in a right-associative manner.open fun <A> Kind<F, A>.reduceRightOption(f: (A, Eval<A>) -> Eval<A>): Eval<Option<A>>
reduceRightToOption open fun <A, B> Kind<F, A>.reduceRightToOption(f: (A) -> B, g: (A, Eval<B>) -> Eval<B>): Eval<Option<B>>
sequence_ Sequence F<G> using Applicative.open fun <G, A> Kind<F, Kind<G, A>>.sequence_(ag: Applicative<G>): Kind<G, Unit>
size The size of this Foldable.open fun <A> Kind<F, A>.size(MN: Monoid<Long>): Long
toList open fun <A> Kind<F, A>.toList(): List<A>
traverse_ Traverse F using Applicative.open fun <G, A, B> Kind<F, A>.traverse_(GA: Applicative<G>, f: (A) -> Kind<G, B>): Kind<G, Unit>

Companion Object Functions

iterateRight fun <A, B> ~~iterateRight~~(it: Iterator<A>, lb: Eval<B>): (f: (A, Eval<B>) -> Eval<B>) -> Eval<B>

Inheritors

Crosswalk interface Crosswalk<T> : Functor<T>, Foldable<T>
Reducible interface Reducible<F> : Foldable<F>
Traverse interface Traverse<F> : Functor<F>, Foldable<F>

Type Class Hierarchy

Do you like Arrow?

Arrow Org
<