5 Sequential programs

In this chapter you will learn

  • how to deal with lists of lists using flatten
  • how to write sequential programs using flatMap instead of for loops
  • how to write sequential programs in a readable way using for comprehensions
  • how to use conditions inside for comprehensions
  • how to get to know more types that have flatMap

Inside every large program is a small program struggling to get out.

—Tony Hoare, “Efficient Production of Large Programs”

Writing pipeline-based algorithms

One of the most popular patterns in modern programming languages is pipelining. We can write many computations as a sequence of operations—a pipeline—that together make a bigger, more involved operation. It’s a different take on creating sequential programs ...

Get Grokking Functional Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.