Book Image

Mastering JavaScript Functional Programming

By : Federico Kereki
Book Image

Mastering JavaScript Functional Programming

By: Federico Kereki

Overview of this book

Functional programming is a programming paradigm for developing software using functions. Learning to use functional programming is a good way to write more concise code, with greater concurrency and performance. The JavaScript language is particularly suited to functional programming. This book provides comprehensive coverage of the major topics in functional programming with JavaScript to produce shorter, clearer, and testable programs. You’ll delve into functional programming; including writing and testing pure functions, reducing side-effects, and other features to make your applications functional in nature. Specifically, we’ll explore techniques to simplify coding, apply recursion for loopless coding, learn ways to achieve immutability, implement design patterns, and work with data types. By the end of this book, you’ll have developed the JavaScript skills you need to program functional applications with confidence.
Table of Contents (22 chapters)
Title Page
About the Author
About the Reviewer
Customer Feedback
Connecting Functions - Pipelining and Composition
Answers to Questions

Chapter 7. Transforming Functions - Currying and Partial Application

In Chapter 6, Producing Functions - Higher-Order Functions, we saw several ways of manipulating functions, to get new versions with some change in their functionality. In this chapter, we will go into a particular kind of transformation, a sort of factory method, that lets you produce new versions of any given function, with some fixed arguments.

We will be considering the following:

  • Currying, a classic FP theoretical function that transforms a function with many parameters into a sequence of unary functions
  • Partial application, another time-honored FP transformation, which produces new versions of functions by fixing some of their arguments
  • Something I'll call partial currying, that can be seen as a mixture of the two previous transformations

To be fair, we'll also see that some of these techniques can be emulated, with possibly greater clarity, by simple arrow functions. However, since you are quite liable to find currying...