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

Using recursion

Recursion is a key technique in FP, to the degree that there are some languages that do not provide for any kind of iteration or loops and work exclusively with recursion (Haskell, which we already mentioned, is a prime example of that). A basic fact of computer science is that whatever you can do with recursion, you can also do with iteration (loops), and vice versa. The key concept is that there are many algorithms whose definition is far easier if you work recursively. On the other hand, recursion is not always taught, or many programmers, even knowing about it, prefer not to use it. So, in this section we shall see several examples of recursive thinking, so you can adapt it for your functional coding.


A typical, oft-quoted, and very old, computer joke! Dictionary definition:recursion: (n) see recursion

But, what is recursion? There are many ways to define what recursion is, but the simplest one I've seen runs along the lines of a function calls itself, again and again...