#### Overview of this book

Scala Functional Programming Patterns
Credits
Aknowledgement
www.PacktPub.com
Preface
Free Chapter
Grokking the Functional Way
Singletons, Factories, and Builders
Recursion and Chasing your Own Tail
Lazy Sequences – Being Lazy, Being Good
Taming Multiple Inheritance with Traits
Of Visitors and Chains of Responsibilities
Traversals – Mapping/Filtering/Folding/Reducing
Higher Order Functions
Actors and Message Passing
Index

In the above, `flatMap` binds stuff together. All the combinator blocks are closure blocks. The `map` block, for example, is accessing variables from its enclosing scopes. And all blocks are returning back a list of strings.

What does a `flatMap` do? It maps and then flattens the result. For example, the following is a way to pick up numbers from `List[Any]`. Using a map does not fully cut it:

```scala> val l = List(1, "this", 2, 4.4, 'c')
l: List[Any] = List(1, this, 2, 4.4, c)

scala> l map {
|   case i: Int => Some(i)
|   case _ => None
| }
res0: List[Option[Int]] = List(Some(1), None, Some(2), None, None)
```

We just need the numbers; however, we get them wrapped up in `Some` or we get them wrapped up in `None`. We have already seen both how we could collect and a partial function for picking up numbers:

```scala> l flatMap {
|   case i: Int => Some(i)
|   case _ => None
| }
res1: List[Int] = List(1, 2)
```

So, `flatMap` does both the mapping (invoking the...