Grokking Functional Programming
Aslam Khan
  • MEAP began June 2014
  • Publication in July 2019 (estimated)
  • ISBN 9781617291838
  • 475 pages (estimated)

Grokking Functional Programming is a practical book. Written especially for object-oriented programmers, it will help you map familiar ideas like objects and inheritance to FP concepts such as programming with immutable data, higher order functions, composing functions, concurrent programming and even the dreaded monad. And you'll be pleased to know that we skip the academic baggage of lambda calculus, category theory, and the mathematical foundations of FP in favor of applying functional programming to everyday programming tasks. At the end of the book, you'll be ready to pick a functional language and start writing useful software.

Table of Contents detailed table of contents


1. Learning Functional Programming

Perhaps you picked up this book because…​

Don’t read this book if…​

What do you need to know before we start?

What language are we going to use?

What this book expects of you

Where does functional programming fit?

Not just programming in a new language

Get our tools ready

What tools can we use?

A little functional fun

Abbreviating names explained

Coffee Break exercises explained

More fun with Strings

Fun with Strings explained


2. Referential Transparency

What is interesting about maths functions?

Why do we have such high trust in maths?

A review of the quick exercises

A second reason to trust maths: no side effects

What just happened to our classes?

Going closer to purity

Another Quick Exercise

Review of Exercise #3

Referential Transparency is why we trust maths

Steps to achieving referential transparency

One last exercise

Review of Exercise #4

From Java to Scala: does an FP language help us?

Defining Immutable objects with Scala

Experiencing Immutable objects with Scala

Experiments with Immutable collections

Using immutable collections in Scala

Aggregation over immutable collections

PAUSE: Where are we?

Where to from here?


Persistent Data Structures

Higher Order Functions

Multi-threading and Concurrency


3. Programming with Immutable Collections

Programming with immutability is strange

Immutability at block scope

How do we add a list of numbers in our head?

Another way to think about looping

Implementing loops without loops in code

No loops: a recursive sum function in Scala

We still value expression of purpose with functions

A Scala way to hide our recursive implementation

Counting recursively

Using a local function for the recursive count

Practicing Recursion

Solutions to our recursion practice exercises

Nasty recursive functions

When can recursion cause a stack overflow?

How to cause a stack overflow in a few lines

Visualising the different recursion functions

Time to catch our breath

We still value DRY - Don’t Repeat Yourself

What shall we name our DRY recursive function?

Passing in code so that we still honor DRY

Passing code into foldLeft with Scala

Understanding Scala’s built-in foldLeft function

Playing with Scala’s foldLeft function

Playing with Scala’s foldLeft explained


4. Immutable Collections

Functions for programming immutable collections

How to add elements to a mutable list

How to add elements to an immutable list

Heads and Tails: Another way to think about lists

Some observations about immutable lists

A Simple linked list

Simple Linked List: Prepend or append?

Simple Linked List: Concatenating two lists

Coffee Break: Reverse a linked list

Coffee Break Explained: Reverse a linked list

Linked Lists: Summary

Another interesting data structure: binary search tree

Binary Search Tree: A Simple Scala Implementation

Binary Search Tree: Structural Sharing

Binary Search Tree: Inserting items

Binary Search Tree: A Path for Depth First Traversal

Coffee Break: Find the maximum value in a tree

Coffee Break Explained: Maximum value in a tree

Binary Search Tree: Summary

Why do we care about persistent data structures?

Transforming persistent data structures

Transforming with filter

Practicing with filter

Transforming with map

Practicing with map

Combining filters and maps into pipelines

Coffee Break: data transformations

Coffee Break Explained: data transformations


5. List Comprehensions

List Comprehensions: An alternative to map and filter

List Comprehensions with Scala: the for-expression

Coffee Break: Simple list comprehensions

Coffee Break Explained: Simple list comprehensions

A Generalisation of a list comprehension

Comprehension over lists of objects

Coffee Break: Working with lists of objects

Coffee Break Explained: Working with lists of objects

Comprehension over lists that have lists

Comprehensions on lists of lists are flatMaps

Relating filter, map and flatMap to comprehensions

Working with multiple lists

Coffee Break: Working with multiple lists

Coffee Break Explained: Working with multiple lists

List Comprehensions or filter, map and flatMap?


6. Immutable Data Structures

Our journey of learning to program with immutability

Boolean: A really simple immutable data structure

Coffee Break: Extend the SwitchState data structure

Coffee Break Explained: Extend the SwitchState

Recursive data structures

Implementing a tree as a sum type data structure

Coffee Break: Find the size of a tree

Coffee Break Explained: Finding the size of a tree

Data structures that are combinations of elements

Programming with immutable data structures

Thinking in Data Structures is thinking in Types

Coffee Break: More types for the Turtle

Coffee Break Explained: More types for the Turtle

Interesting applications of functional data structures

Category Theory and Algebraic Data Types


7. Higher Order Functions (HOFs)

Why should we bother with higher order functions?

A look at concise code with higher order functions

Concise code tends to be declaritive code

What is a higher order function?

A higher order function receives functions as inputs

Coffee Break: functions that receive functions

Coffee Break: functions that receive functions

A higher order function can return a function as output

Binding input data to returned functions

Coffee Break: functions that return functions

Coffee Break: functions that return functions

Functions as Types

Designing with Functions and Data as Types

Wrap-up: Abstractions with Functions and Data Types

Coffee Break: Designing with Functions and Data

Coffee Break: Designing with Functions and Data


Binding data to functions



Data stream programming

Concurrency with Actors


User Interface programming

Web application programming

Pure Simon Says


About the Technology

Functional programming is more than just writing the same old code in Scala, Clojure, or Haskell. To grok FP—to really get it—you need to rewire your brain to see the world differently. We're here to help you flip the switch. Grokking Functional Programming teaches you first to break down problems in a new way so you can approach them from a FP mindset. Following carefully-selected examples with thorough, carefully-paced explanations, you'll immerse yourself in FP concept by concept. Along the way, exercises, checks for understanding, and even the occasional puzzler give you opportunities to think and practice what you're learning.

What's inside

  • Designing with functions instead of objects
  • Multiple learning approaches to help you grok each new concept
  • A practical programming-first teaching style
  • Programming with immutable collections
  • Writing concurrent programs with a functional style

About the reader

Examples use Scala as the teaching language, but this is not a Scala book. No prior knowledge of Scala or FP is required.

About the author

Aslam Khan is an African software developer whose foray into functional programming was out of necessity, not curiosity. Aslam uses FP daily for production work.

Manning Early Access Program (MEAP) Read chapters as they are written, get the finished eBook as soon as it’s ready, and receive the pBook long before it's in bookstores.
MEAP combo $44.99 pBook + PDF
MEAP eBook $35.99 PDF only

placing your order...

Don't refresh or navigate away from the page.

FREE domestic shipping on three or more pBooks