About the Authors |
|
xi | |
About the Technical Reviewer |
|
xiii | |
Acknowledgments |
|
xv | |
Introduction |
|
xvii | |
|
Chapter 1 Functional Programming in Simple Terms |
|
|
1 | (20) |
|
What Is Functional Programming? Why Does It Matter? |
|
|
2 | (3) |
|
|
5 | (2) |
|
Imperative, Declarative, Abstraction |
|
|
7 | (1) |
|
Functional Programming Benefits |
|
|
8 | (1) |
|
|
8 | (9) |
|
Pure Functions Lead to Testable Code |
|
|
9 | (2) |
|
|
11 | (1) |
|
|
12 | (2) |
|
|
14 | (2) |
|
|
16 | (1) |
|
A Pure Function Is a Mathematical Function |
|
|
17 | (1) |
|
What We Are Going to Build |
|
|
18 | (1) |
|
Is JavaScript a Functional Programming Language? |
|
|
19 | (1) |
|
|
20 | (1) |
|
Chapter 2 Fundamentals of JavaScript Functions |
|
|
21 | (20) |
|
ECMAScript: A Bit of History |
|
|
22 | (1) |
|
Creating and Executing Functions |
|
|
23 | (7) |
|
|
24 | (2) |
|
|
26 | (2) |
|
Return Statement Is Optional |
|
|
28 | (1) |
|
Multiple Statement Functions |
|
|
28 | (2) |
|
|
30 | (1) |
|
ES5 Functions Are Valid in ES6 and Above |
|
|
30 | (1) |
|
|
30 | (10) |
|
|
31 | (2) |
|
Our First Functional Approach to the Loop Problem |
|
|
33 | (3) |
|
|
36 | (1) |
|
|
36 | (1) |
|
Running the Code Using Babel-Node |
|
|
37 | (1) |
|
|
38 | (1) |
|
Running the Source Code from Git |
|
|
39 | (1) |
|
|
40 | (1) |
|
Chapter 3 Higher Order Functions |
|
|
41 | (22) |
|
|
42 | (5) |
|
Understanding JavaScript Data Types |
|
|
42 | (1) |
|
|
43 | (1) |
|
|
44 | (1) |
|
|
45 | (2) |
|
Abstraction and Higher Order Functions |
|
|
47 | (6) |
|
|
48 | (1) |
|
Abstraction via Higher Order Functions |
|
|
48 | (5) |
|
Higher Order Functions in the Real World |
|
|
53 | (8) |
|
|
53 | (2) |
|
|
55 | (1) |
|
|
56 | (5) |
|
|
61 | (2) |
|
Chapter 4 Closures and Higher Order Functions |
|
|
63 | (18) |
|
|
64 | (6) |
|
|
64 | (3) |
|
Remembering Where It Is Born |
|
|
67 | (2) |
|
Revisiting sortBy Function |
|
|
69 | (1) |
|
Higher Order Functions in the Real World (Continued) |
|
|
70 | (10) |
|
|
70 | (2) |
|
|
72 | (2) |
|
|
74 | (1) |
|
|
75 | (3) |
|
|
78 | (2) |
|
|
80 | (1) |
|
Chapter 5 Being Functional on Arrays |
|
|
81 | (28) |
|
Working Functionally on Arrays |
|
|
82 | (6) |
|
|
82 | (5) |
|
|
87 | (1) |
|
|
88 | (7) |
|
|
90 | (5) |
|
|
95 | (7) |
|
|
95 | (7) |
|
|
102 | (6) |
|
|
105 | (3) |
|
|
108 | (1) |
|
Chapter 6 Currying and Partial Application |
|
|
109 | (24) |
|
A Few Notes on Terminology |
|
|
110 | (2) |
|
|
110 | (1) |
|
|
110 | (1) |
|
|
110 | (2) |
|
|
112 | (11) |
|
|
114 | (2) |
|
A logger Function: Using Currying |
|
|
116 | (1) |
|
|
117 | (5) |
|
|
122 | (1) |
|
|
123 | (2) |
|
Finding a Number in Array Contents |
|
|
124 | (1) |
|
|
124 | (1) |
|
|
125 | (5) |
|
|
125 | (2) |
|
Implementing partial Function |
|
|
127 | (3) |
|
Currying vs. Partial Application |
|
|
130 | (1) |
|
|
130 | (3) |
|
Chapter 7 Composition and Pipelines |
|
|
133 | (24) |
|
Composition in General Terms |
|
|
134 | (3) |
|
|
134 | (3) |
|
|
137 | (3) |
|
|
137 | (2) |
|
|
139 | (1) |
|
Playing with the compose Function |
|
|
140 | (8) |
|
Curry and partial to the Rescue |
|
|
142 | (4) |
|
|
146 | (2) |
|
|
148 | (7) |
|
|
149 | (1) |
|
|
150 | (1) |
|
|
151 | (3) |
|
Debugging Using the tap Function |
|
|
154 | (1) |
|
|
155 | (2) |
|
Chapter 8 Fun with Functors |
|
|
157 | (24) |
|
|
158 | (5) |
|
|
158 | (3) |
|
|
161 | (2) |
|
|
163 | (10) |
|
|
163 | (2) |
|
|
165 | (3) |
|
|
168 | (5) |
|
|
173 | (6) |
|
|
174 | (2) |
|
Reddit Example Either Version |
|
|
176 | (3) |
|
Word of Caution: Pointed Functor |
|
|
179 | (1) |
|
|
180 | (1) |
|
Chapter 9 Monads in Depth |
|
|
181 | (24) |
|
Getting Reddit Comments for Our Search Query |
|
|
182 | (1) |
|
|
183 | (13) |
|
Implementation of the First Step |
|
|
185 | (4) |
|
|
189 | (5) |
|
Problem of Nested/Many maps |
|
|
194 | (2) |
|
Solving the Problem via join |
|
|
196 | (7) |
|
|
196 | (4) |
|
|
200 | (3) |
|
|
203 | (2) |
|
Chapter 10 Pause, Resume, and Async with Generators |
|
|
205 | (36) |
|
Async Code and Its Problem |
|
|
206 | (3) |
|
|
206 | (3) |
|
|
209 | (10) |
|
|
209 | (1) |
|
|
210 | (1) |
|
|
211 | (3) |
|
Done Property of Generator |
|
|
214 | (2) |
|
Passing Data to Generators |
|
|
216 | (3) |
|
Using Generators to Handle Async Calls |
|
|
219 | (11) |
|
Generators for Async: A Simple Case |
|
|
219 | (7) |
|
Generators for Async: A Real-World Case |
|
|
226 | (4) |
|
Async Functions in ECMAScript 2017 |
|
|
230 | (9) |
|
|
230 | (1) |
|
|
231 | (1) |
|
|
231 | (2) |
|
|
233 | (3) |
|
Error Handling in Async Calls |
|
|
236 | (1) |
|
Async Functions Transpiled to Generators |
|
|
237 | (2) |
|
|
239 | (2) |
|
Chapter 11 Building a React-Like Library |
|
|
241 | (28) |
|
|
242 | (3) |
|
Building a Simple Redux Library |
|
|
245 | (6) |
|
Building a Framework Like HyperApp |
|
|
251 | (17) |
|
|
252 | (2) |
|
|
254 | (1) |
|
|
255 | (6) |
|
|
261 | (1) |
|
|
262 | (1) |
|
|
263 | (1) |
|
|
264 | (1) |
|
|
265 | (1) |
|
|
266 | (2) |
|
|
268 | (1) |
|
Chapter 12 Testing and Closing Thoughts |
|
|
269 | (30) |
|
|
270 | (2) |
|
|
272 | (1) |
|
|
273 | (1) |
|
JavaScript Test Frameworks |
|
|
274 | (16) |
|
|
275 | (8) |
|
|
283 | (4) |
|
|
287 | (3) |
|
|
290 | (1) |
|
|
291 | (3) |
|
Unit Testing Library Code |
|
|
294 | (2) |
|
|
296 | (1) |
|
|
297 | (2) |
Index |
|
299 | |