liveBook · Manning

Foldable

Foldable is a typeclass abstraction for data structures whose elements can be traversed and reduced to a result by folding operations.

How 2 Manning books explain it

Functional Programming in Scala, Second Edition

A foldable data type is a data type whose elements can be traversed and reduced to a result by a folding operation.

How it is used
Abstracts reductions over different container shapes through foldLeft, foldRight, foldMap, and combineAll.
How deep it goes
Derives fold operations, compares implementation choices, and implements instances for List, IndexedSeq, LazyList, Tree, and Option.
Examples
Uses integer summation, List, IndexedSeq, LazyList, Tree, Option, conversion to List, and frequency-map construction.
What you can do after
Build it from scratch by defining and optimizing Foldable instances and deriving reusable reductions.

Read how Functional Programming in Scala, Second Edition explains foldable →

Learn Haskell by Example

Foldable is a Haskell type class for data structures whose elements can be traversed and reduced by folding operations.

How it is used
Generalizes list reduction across traversable data structures and supplies convenient aggregate operations.
How deep it goes
Defines fold directions, gives recursive implementations, and stops short of showing the binary-tree instance code.
Examples
Uses candy trails, fruity-candy collection, last-five collection, binary trees, and expression-building folds.
What you can do after
Build it from scratch by implementing fold-based helpers and a Foldable instance for a binary tree.

Read how Learn Haskell by Example explains foldable →

Related concepts

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.