# 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

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

### Companion Object Functions

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

### Inheritors

 Crosswalk `interface Crosswalk : ``Functor``, ``Foldable``` Reducible `interface Reducible : ``Foldable``` Traverse `interface Traverse : ``Functor``, ``Foldable```

## Type Class Hierarchy

Do you like Arrow?

<