liveBook · Manning

Traverse

traverse is an operation that applies an effectful function to each element of a structure and combines the resulting effects into one effect containing the transformed structure.

How 2 Manning books explain it

Functional Programming in Scala, Second Edition

A traversable functor is an abstraction that systematically applies an effectful function to the elements of a data structure and combines the resulting effects.

How it is used
Combines effectful element transformations while preserving the surrounding collection shape.
How deep it goes
Derives List implementations with foldRight and map2, then generalizes them to Traverse, State, fusion, nesting, and monad composition.
Examples
Uses parsing strings with Option, Either validation, candy-machine State actions, element numbering, and List, Option, Tree, and Map instances.
What you can do after
Build it from scratch for List, Option, Either, and State, then generalize it as a Traverse instance.

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

Functional Programming in C#, Second Edition

A traversal operation that uses applicative composition to combine effects from applying a function to each item.

How it is used
Combines effectful results across a structure or reverses the order of nested effects.
How deep it goes
Derives an Aggregate-based implementation and contrasts monadic and applicative reducers, including a single-value traversal.
Examples
Uses comma-separated number parsing, multiple validators for a country code, and airline fare searches.
What you can do after
Build it from scratch using Aggregate and apply it to validation and asynchronous searches.

Read how Functional Programming in C#, Second Edition explains traverse →

Also covered in

What to know first

Related concepts

Questions about traverse

What is traverse?

traverse is an operation that applies an effectful function to each element of a structure and combines the resulting effects into one effect containing the transformed structure.

Which Manning books explain traverse?

Functional Programming in Scala, Second Edition and Functional Programming in C#, Second Edition.

What should I know before learning traverse?

Manning books that teach traverse usually introduce list, applicative functor, identity function and monad first.

What is the difference between traverse and map?

traverse is an operation that applies an effectful function to each element of a structure and combines the resulting effects into one effect containing the transformed structure. Map is an operation that applies a function to values in a collection or computational context and returns the results while preserving the structure or context.

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.