Grokking Functional Programming
Michał Płachta
  • MEAP began June 2014
  • Publication in Spring 2021 (estimated)
  • ISBN 9781617291838
  • 475 pages (estimated)
  • printed in black & white

An absolutely wonderful book for someone that has tried and failed to understand functional programming.

William E. Wheeler
Grokking Functional Programming is a practical book written especially for object-oriented programmers. It will help you map familiar ideas like objects and composition to FP concepts such as programming with immutable data and higher-order functions. You will learn how to write concurrent programs, how to handle errors and how to design your solutions with modularity and readability in mind. 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 and maintainable software.

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.
Table of Contents detailed table of contents

Part 1: The Functional Toolkit

1 Learning functional programming

1.1 Perhaps you picked up this book because…​

1.2 What do you need to know before we start?

1.3 What do functions look like?

1.4 Meet the function

1.5 When the code lies…​

1.6 Imperative vs declarative

1.7 Coffee Break: imperative vs declarative

1.8 Coffee Break Explained: imperative vs declarative

1.9 How useful is learning functional programming?

1.10 Leaping into Scala

1.11 Practicing functions in Scala

1.12 Getting our tools ready

1.13 Getting to know the Scala REPL

1.14 Writing your first functions!

1.15 How to use this book?

1.16 Summary

2 Pure Functions

2.1 Why do we need pure functions?

2.2 Coding imperatively

2.3 Breaking the code

2.4 Passing copies of the data

2.5 Breaking the code…​ again

2.6 Recalculating instead of storing

2.7 Focusing on logic by passing the state

2.8 Where did all the state go?

2.9 Difference between impure & pure functions

2.10 Coffee Break: refactoring to a pure function

2.11 Coffee Break explained: refactoring to a pure function

2.12 In pure functions we trust

2.13 Pure functions in programming languages

2.14 Difficulty of staying pure…​

2.15 Pure functions and clean code

2.16 Coffee Break: pure or impure?

2.17 Coffee Break Explained: pure or impure?

2.18 Using Scala to write pure functions

2.19 Practicing pure functions in Scala

2.20 Testing pure functions

2.21 Coffee Break: testing pure functions

2.22 Coffee Break Explained: testing pure functions

2.23 Summary

3 Immutable Values

3.1 The fuel for the engine

3.2 Another case for immutability

3.3 Can you trust this function?

3.4 Mutability is dangerous

3.5 Functions that lie…​ again

3.6 Fighting mutability by working with copies

3.7 Coffee Break: getting burnt by mutability

3.8 Coffee Break Explained: getting burnt by mutability

3.9 Introducing shared mutable state

3.10 State’s impact on programming abilities

3.11 Dealing with the moving parts

3.12 Dealing with the moving parts using FP

3.13 Immutable values in Scala

3.14 Building our intuitions about immutability

3.15 Coffee Break: The Immutable String API

3.16 Coffee Break Explained: The Immutable String API

3.17 Hold on…​ isn’t this bad?

3.18 Purely functional approach to the shared mutable state

3.19 Practicing immutable slicing and appending

3.20 Summary

4 Functions as Values

4.1 Implementing requirements as functions

4.2 Impure functions and mutable values strike again

4.3 Using Java Streams to sort the list

4.4 Function signatures should tell the whole story

4.5 Changing the requirements

4.6 We just pass the code around!

4.7 Using Java’s Function values

4.8 Using Function syntax to deal with code duplication

4.9 Passing user-defined functions as arguments

4.10 Coffee Break: Functions as Parameters

4.11 Coffee Break Explained: Functions as Parameters

4.12 Problems with reading functional Java

4.13 Passing functions in Scala

4.14 Deep dive into sortBy

4.15 Solving the word ranking problem using Scala

4.16 Implementing a word ranker in Scala

4.17 Practicing function passing

4.18 Implementing a word ranker in a declarative way

4.19 Passing functions to custom-made functions

4.20 Small functions and their responsibilities

4.21 Passing functions inline

4.22 Coffee Break: Passing functions in Scala

4.23 Coffee Break Explained: Passing functions in Scala

4.24 What else can we achieve just by passing functions?

4.25 Applying a function to each element of a list

4.26 Applying a function to each element of a list using map

4.27 Getting to know map

4.28 Practicing map

4.29 Learn once, use everywhere

4.30 Returning parts of the list based on a condition

4.31 Returning parts of the list using filter

4.32 Getting to know filter

4.33 Practicing filter

4.34 Our journey so far…​

4.35 Don’t repeat yourself?

4.36 Is my API easy to use?

4.37 Adding a new parameter is not enough

4.38 Functions can return functions

4.39 Using functions that can return functions

4.40 Functions are values

4.41 Coffee Break: Returning functions

4.42 Coffee Break Explained: Returning functions

4.43 Designing functional APIs

4.44 Iterative design of functional APIs

4.45 Returning functions from returned functions

4.46 How to return functions from returned functions?

4.47 Using the flexible API built with returned functions

4.48 Using multiple parameter lists in functions

4.49 We have been currying!

4.50 Practicing currying

4.51 Programming by passing function values

4.52 Reducing many values into one value

4.53 Reducing many values into one value using foldLeft

4.54 Getting to know foldLeft

4.55 foldLeft varia

4.56 Practicing foldLeft

4.57 Modeling immutable data

4.58 Using case classes with higher-order functions

4.59 More concise syntax for inline functions

4.60 Summary

Part 2: Functional Programs

5 Sequential programs

5.1 Writing pipeline-based algorithms

5.2 Pipeline #1: recommending book adaptations

5.3 The imperative approach

5.4 flatten and flatMap

5.5 Practical use case of using more flatMaps

5.6 flatMap and changing the size of the list

5.7 Coffee Break: Dealing with lists of lists

5.8 Coffee Break Explained: Dealing with lists of lists

5.9 Chained flatMaps & maps

5.10 Nested flatMaps

5.11 Values that depend on other values

5.12 Practicing nested flatMaps

5.13 Better syntax for nested flatMaps

5.14 For comprehensions to the rescue!

5.15 Coffee Break: flatMaps vs for comprehensions

5.16 Coffee Break explained: flatMaps vs for comprehensions

5.17 Getting to know for comprehensions

5.18 It’s not the for you are looking for!

5.19 Defining for comprehension

5.20 Pipeline #2: Is a point inside a given circle?

5.21 Checking all combinations using a for comprehension

5.22 Filtering techniques

5.23 Coffee Break: Filtering techniques

5.24 Coffee Break Explained: Filtering techniques

5.25 Looking for greater abstraction

5.26 Comparing map, foldLeft and flatMap

5.27 Using for comprehension with Sets

5.28 Using for comprehension with many types

5.29 Practicing for comprehensions

5.30 Defining for comprehension…​ again

5.31 Pipeline #3: parsing historical events

5.32 Avoiding nulls: Option type

5.33 Parsing as a pipeline

5.34 Coffee Break: Parsing with Option

5.35 Coffee Break Explained: Parsing with Option

5.36 Summary

6 Error Handling

6.1 Handling lots of different errors, gracefully

6.2 Is it even possible to handle them all?

6.3 Sort the list of TV shows by their running time

6.4 Implementing the sorting requirement

6.5 Dealing with data coming from the outside world

6.6 Functional design: building from small blocks

6.7 Parsing Strings into immutable objects

6.8 Parsing a List is just parsing one element

6.9 Parsing a String into aTvShow

6.10 What about potential errors?

6.11 Is returning null a good idea?

6.12 How to handle potential errors more gracefully?

6.13 Implementing a function that returns an Option

6.14 Option forces us to handle possible errors

6.15 Building from small blocks

6.16 Functional design is building from small blocks

6.17 Writing a small safe function that returns an Option

6.18 Functions, values and expressions

6.19 Practicing safe functions that return Options

6.20 How do errors propagate?

6.21 Values represent errors

6.22 Option, for comprehension and checked exceptions…​

6.23 What about checked exceptions?

6.24 Conditional recovery

6.25 Conditional recovery using imperative style

6.26 Conditional recovery using functional style

6.27 Checked exceptions don’t compose—Options do!

6.28 How does orElse work?

6.29 Practicing functional error handling

6.30 Functions compose, even in the presence of errors

6.31 Compiler reminds us that errors need to be covered

6.32 Compilation errors are good for us!

6.33 Transforming List of Options into a List

6.34 Let the compiler be our guide…​

6.35 …​but let’s not trust the compiler too much!

6.36 Coffee Break: Error handling logic

6.37 Coffee Break Explained: Error handling logic

6.38 Two different error handling strategies

6.39 All-or-nothing error handling strategy

6.40 Folding a List of Options into an Option of a List

6.41 We now know how to handle multiple possible errors!

6.42 How to know what failed?

6.43 We need to convey error details in the return value

6.44 Conveying error details using Either

6.45 Refactoring to Either

6.46 Returning an Either instead of an Option

6.47 Practicing safe functions that return Either

6.48 What we learned about Option works with Either

6.49 Coffee Break: Error handling using Either

6.50 Coffee Break Explained: Error handling using Either

6.51 Working with Option/Either

6.52 Summary

7 Requirements as Types

8 IO

9 Concurrent Programs

10 Data Streams

11 Testing

12 Mechanics of Functional Programs

Part 3: Applied Functional Programming

13 Case Study #1

14 Case Study #2

15 Case Study #3

What's inside

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

About the reader

The book assumes that the reader has at least one year of experience developing software using a mainstream object-oriented programming language like Java. While examples use Scala, this is not a Scala book. The concepts will apply to any FP language, and no prior knowledge of Scala or FP is required.

About the author

Michał Płachta started using Scala commercially in 2014 and has been an active contributor to the Scala and JVM communities since. He regularly speaks at conferences, runs workshops, and organizes meetups to help others become better at functional programming. You can find his blog at

placing your order...

Don't refresh or navigate away from the page.
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.
print book $29.99 $44.99 pBook + eBook + liveBook
Additional shipping charges may apply
Grokking Functional Programming (print book) added to cart
continue shopping
go to cart

eBook $24.99 $35.99 3 formats + liveBook
Grokking Functional Programming (eBook) added to cart
continue shopping
go to cart

Prices displayed in rupees will be charged in USD when you check out.

FREE domestic shipping on three or more pBooks