Book Image

Mastering JavaScript Functional Programming - Third Edition

By : Federico Kereki
5 (1)
Book Image

Mastering JavaScript Functional Programming - Third Edition

5 (1)
By: Federico Kereki

Overview of this book

Functional programming is a programming paradigm that uses functions for developing software. This book is filled with examples that enable you to leverage the latest JavaScript and TypeScript versions to produce modern and clean code, as well as teach you to how apply functional programming techniques to develop more efficient algorithms, write more concise code, and simplify unit testing. This book provides comprehensive coverage of the major topics in functional programming to produce shorter, clearer, and testable programs. You’ll begin by getting to grips with writing and testing pure functions, reducing side effects, as well as other key features to make your applications functional in nature. The book specifically explores techniques to simplify coding, apply recursion, perform high-level 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 practical programming skills needed to confidently enhance your applications by adding functional programming to wherever it’s most suitable.
Table of Contents (17 chapters)
14
Bibliography

Using functions in FP ways

Several common coding patterns take advantage of the FP style, even if you aren’t aware of it. In this section, we will go through them and look at the functional aspects of the code so that you can get more accustomed to this coding style.

Then, we’ll look in detail at using functions in an FP way by considering several FP techniques, such as the following:

  • Injection, which is needed for sorting different strategies, as well as other uses
  • Callbacks and promises, introducing the continuation-passing style
  • Polyfilling and stubbing
  • Immediate invocation schemes

Injection – sorting it out

The Array.prototype.sort() method provides the first example of passing functions as parameters. If you have an array of strings and you want to sort it, you can just use the sort() method. For example, to alphabetically sort an array with the colors of the rainbow, we would write something like the following:

// sort...