Functional-Light JavaScript
Balanced, Pragmatic FP in JavaScript
Kyle Simpson
  • May 2019
  • ISBN 9781617296512
  • 381 pages
This title is out of print and no longer for sale.
Functional programming (FP) is a powerful coding style for creating programs that are modular, reusable, concise, and easy to read, test, and debug. For developers used to a procedural style, however, the unfamiliar terminology and mathematical notations can seem daunting at first. Functional-Light JavaScript eases you into FP, covering the concepts, terminology, and practices that give you the greatest benefit. It takes a practical approach to the most important aspects of FP—function purity, value immutability, composition, and more—with a focus on applying what you learn. Through engaging instruction and crystal-clear JavaScript examples, you’ll learn this game-changing programming style from the ground up!

Distributed by Manning Publications

This book was created independently by JavaScript expert Kyle Simpson and is distributed by Manning Publications.

About the Technology

Based on the sound mathematical principle of composing independent units of reliably correct code into computational systems, functional programming offers substantial benefits for the long-term reliability of your applications. The style emphasizes modularity, reusability, and ease of testing and debugging. Because each function in the system is provably correct by design, your code is verifiable, reliable, and free of many common bugs associated with state and scope.

Functional-Light Programming (FLP) is an approach pioneered by author Kyle Simpson, with JavaScript in mind. This technique distills all the most beneficial parts of FP—including function purity, composition, closure, immutability, iterations, recursion, and others—into practical patterns that you can easily learn without getting bogged down by complex terminology, symbology, or overly strict adherence to principles.

About the book

Functional-Light JavaScript teaches you to apply the core principles of FP to your JavaScript code, with a balanced, pragmatic approach. In his friendly, informal style, author Kyle Simpson walks you through the basic concepts of FP, like trust, communication, readability, and perspective. You’ll learn the nature of functions, how to manage function inputs, and how to reduce side effects with pure functions. You’ll also explore value immutability, closure, recursion, and list operations like map, reduce, and filter.

With the foundational concepts securely under your belt, you’ll advance to asynchronous processing concepts, including managing time as state, reducing time dependencies, eager versus lazy processing, Observables, and Promises. Every chapter wraps up with a clear and concise summary, locking in your new knowledge. In the final chapter, you’ll discover a complete application that ties together everything you’ve learned, including clearly explained code. When you’re done reading this invaluable book, you’ll have the FP skills you need to write programs that yield all the benefits of this powerful coding style, including taking your software career to the next level!
Table of Contents detailed table of contents

1. Why Functional Programming?

1.1. At a Glance

1.2. Confidence

1.3. Communication

1.4. Readability

1.5. Perspective

1.6. How to Find Balance

1.7. Resources

1.7.1. Books

1.7.2. Blogs/sites

1.7.3. Libraries

1.8. Summary

2. The Nature Of Functions

2.1. What Is a Function?

2.1.1. Brief Math Review

2.1.2. Function vs Procedure

2.2. Function Input

2.2.1. Defaulting Parameters

2.2.2. Counting Inputs

2.2.3. Arrays of Arguments

2.2.4. Parameter Destructuring

2.2.5. The Importance of Declarative Style

2.3. Named Arguments

2.3.1. Unordered Parameters

2.4. Function Output

2.4.1. Early Returns

2.4.2. Unreturned Outputs

2.5. Functions of Functions

2.5.1. Keeping Scope

2.6. Syntax

2.6.1. What’s in a Name?

2.6.2. Functions Without function

2.7. What’s This?

2.8. Summary

3. Managing Function Inputs

3.1. All for One

3.2. One on One

3.2.1. Unchanging One

3.3. Adapting Arguments to Parameters

3.4. Some Now, Some Later

3.4.1. bind(..)

3.4.2. Reversing Arguments

3.5. One at a Time

3.5.1. Visualizing Curried Functions

3.5.2. Why Currying and Partial Application?

3.5.3. Currying More Than One Argument?

3.5.4. No Curry for Me, Please

3.6. Order Matters

3.6.1. Spreading Properties

3.7. No Points

3.8. Summary

4. Composing Functions

4.1. Output to Input

4.1.1. Machine Making

4.1.2. Composition Variation

4.2. General Composition

4.2.1. Alternative Implementations

4.3. Reordered Composition

4.4. Abstraction

4.4.1. Separation Enables Focus

4.4.2. Composition as Abstraction

4.5. Revisiting Points

4.6. Summary

5. Reducing Side Effects

5.1. Effects on the Side, Please

5.1.1. Hidden Causes

5.1.2. I/O Effects

5.1.3. Side Bugs

5.2. Once Is Enough, Thanks

5.2.1. Mathematical Idempotence

5.2.2. Programming Idempotence

5.3. Pure Bliss

5.3.1. Purely Relative

5.4. There or Not

5.4.1. Mentally Transparent

5.4.2. Not So Transparent?

5.5. Purifying

5.5.1. Containing Effects

5.5.2. Covering Up Effects

5.5.3. Evading Effects

5.5.4. this Revisited

5.6. Summary

6. Value Immutability

6.1. Primitive Immutability

6.2. Value to Value

6.2.1. Non-Local

6.3. Reassignment

6.3.1. Intent

6.3.2. It’s Freezing in Here

6.4. Performance

6.5. Treatment

6.6. Summary

7. Closure vs. Object

7.1. The Same Page

7.2. Look Alike

7.2.1. State

7.2.2. Behavior, Too!

7.2.3. (Im)mutability

7.2.4. Isomorphic

7.2.5. Under the Hood

7.3. Two Roads Diverged in a Wood…​

7.3.1. Structural Mutability

7.3.2. Privacy

7.3.3. Cloning State

7.3.4. Performance

7.4. Summary

8. Recursion

8.1. Definition

8.1.1. Mutual Recursion

8.1.2. Why Recursion?

8.2. Declarative Recursion

8.2.1. Binary Tree Recursion

8.3. Stack

8.3.1. Tail Calls

8.3.2. Proper Tail Calls (PTC)

8.4. Rearranging Recursion

8.4.1. Replacing the Stack

8.4.2. Continuation Passing Style (CPS)

8.4.3. Trampolines

8.5. Summary

9. List Operations

9.1. Non-FP List Processing

9.2. Map

9.2.1. Sync vs. Async

9.2.2. Mapping vs. Eaching

9.2.3. A Word: Functors

9.3. Filter

9.3.1. Filtering Confusion

9.3.2. Filtering-Out & Filtering-In

9.4. Reduce

9.4.1. Map as Reduce

9.4.2. Filter as Reduce

9.5. Advanced List Operations

9.5.1. Unique

9.5.2. Flatten

9.5.3. Zip

9.5.4. Merge

9.6. Method vs. Standalone

9.6.1. Composing Method Chains

9.6.2. Composing Standalone Utilities

9.6.3. Adapting Methods to Standalones

9.6.4. Adapting Standalones to Methods

9.7. Looking for Lists

9.8. Fusion

9.9. Beyond Lists

9.10. Summary

10. Functional Async

10.1. Time as State

10.1.1. Reducing Time

10.2. Eager vs. Lazy

10.3. Reactive FP

10.3.1. Declarative Time

10.3.2. More Than Map

10.3.3. Observables

10.4. Summary

11. Putting It All Together

11.1. Setup

11.2. Stock Events

11.3. Stock Ticker UI

11.3.1. Main API

11.3.2. Subscribing to Observables

11.4. Summary


Appendix A: Transducing

A.1. Why, First

A.2. How, Next

A.2.1. Expressing Map/Filter as Reduce

A.2.2. Parameterizing the Reducers

A.2.3. Extracting Common Combination Logic

A.2.4. Parameterizing the Combination

A.2.5. Composing Curried

A.2.6. Alternative Combination

A.3. What, Finally

A.3.1. Transducers.js

A.4. Summary

Appendix B: The Humble Monad

B.1. Type

B.2. Loose Interface

B.3. Just a Monad

B.3.1. Working with Monad Methods

B.4. Maybe

B.4.1. Different Maybes

B.5. Humble

B.5.1. Humility

B.6. Summary

Appendix C: FP Libraries

C.1. Stuff to Investigate

C.2. Ramda (0.23.0)

C.3. Lodash/fp (4.17.4)

C.4. Mori (0.3.2)

C.5. Bonus: FPO

C.6. Bonus #2: fasy

C.7. Summary

C.8. Notes

What's inside

  • Reducing side effects with pure functions
  • Eager versus lazy processing
  • Function composition
  • Value immutability
  • Recursion
  • Closure
  • List operations, including map, filter, and reduce
  • Asynchronous FP principles

About the reader

Functional-Light JavaScript is perfect for developers with intermediate JavaScript experience. No experience with functional programming is necessary.

About the author

Kyle Simpson is an avid proponent of the Open Web, who codes regularly on several open source projects. Passionate about all things JavaScript, he's the author of the popular You Don't Know JS book series and has taught JavaScript in corporate and public workshops all over the world. His online training videos have racked up 325,000 watch hours and counting, and he’s a regular speaker at various web/JS conferences.

placing your order...

Don't refresh or navigate away from the page.
customers also reading

This book 1-hop 2-hops 3-hops

FREE domestic shipping on three or more pBooks