If you’re familiar with functional programming basics and want to gain a much deeper understanding, this in-depth guide takes you beyond syntax and demonstrates how you need to think in a new way. Software architect Neal Ford shows intermediate to advanced developers how functional coding allows you to step back a level of abstraction so you can see your programming problem with greater clarity.
Each chapter shows you various examples of functional thinking, using numerous code examples from Java 8 and other JVM languages that include functional capabilities. This book may bend your mind, but you’ll come away with a much better grasp of functional programming concepts.
View real-world examples of functional thinking with Java 8, and in functional architectures and web frameworks
Preface vii
1 Why 1 (10)
Shifting Paradigms 2 (2)
Aligning with Language Trends 4 (1)
Ceding Control to the Language/Runtime 4 (1)
Concision 5 (6)
2 Shift 11 (28)
A Common Example 11 (6)
Imperative Processing 11 (1)
Functional Processing 12 (5)
Case Study: Number Classification 17 (7)
Imperative Number Classification 17 (2)
Slightly More Functional Number 19 (2)
Classification
Java 8 Number Classifier 21 (1)
Functional Java Number Classifier 22 (2)
Common Building Blocks 24 (7)
Filter 24 (1)
Map 25 (4)
Fold/Reduce 29 (2)
Synonym Suffering 31 (8)
Filter 31 (3)
Map 34 (2)
Fold/Reduce 36 (3)
3 Cede 39 (20)
Iteration to Higher-Order Functions 39 (1)
Closures 40 (4)
Currying and Partial Application 44 (8)
Definitions and Distinctions 44 (1)
In Groovy 45 (2)
In Clojure 47 (1)
Scala 47 (4)
Common Uses 51 (1)
Recursion 52 (4)
Seeing Lists Differently 52 (4)
Streams and Work Reordering 56 (3)
4 Smarter, Not Harder 59 (24)
Memoization 59 (11)
Caching 60 (3)
Adding Memoization 63 (7)
Laziness 70 (13)
Lazy Iterator in Java 70 (2)
Totally Lazy Number Classifier 72 (2)
Lazy Lists in Groovy 74 (3)
Building a Lazy List 77 (3)
Benefits of Laziness 80 (2)
Lazy Field Initialization 82 (1)
5 Evolve 83 (30)
Few Data Structures, Many Operations 83 (2)
Bending the Language Toward the Problem 85 (1)
Rethinking Dispatch 86 (5)
Improving Dispatch with Groovy 86 (1)
Clojure's "Bendable" Language 87 (2)
Clojure Multimethods and a la carte 89 (2)
Polymorphism
Operator Overloading 91 (4)
Groovy 91 (2)
Scala 93 (2)
Functional Data Structures 95 (18)
Functional Error Handling 96 (1)
The Either Class 97 (8)
The Option Class 105(1)
Either Trees and Pattern Matching 106(7)
6 Advance 113(20)
Design Patterns in Functional Languages 113(1)
Function-Level Reuse 114(10)
Template Method 116(2)
Strategy 118(1)
The Flyweight Design Pattern and Memoization 119(3)
Factory and Currying 122(2)
Structural Versus Functional Reuse 124(9)
Code Reuse Via Structure 124(9)
7 Practical Thinking 133(12)
Java 8 133(4)
Functional Interfaces 135(1)
Optional 136(1)
Java 8 Streams 136(1)
Functional Infrastructure 137(8)
Architecture 137(4)
Web Frameworks 141(1)
Databases 142(3)
8 Polyglot and Polyparadigm 145(14)
Combining Functional with Metaprogramming 146(1)
Mapping Data Types with Metaprogramming 147(3)
Infinite Streams with Functional Java and 148(2)
Groovy
Consequences of Multiparadigm Languages 150(1)
Context Versus Composition 151(3)
Functional Pyramid 154(5)
Index 159