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


10.1. Freezing by proxying. In the Chaining and Fluent Interfacessection of Chapter 8, Connecting Functions - Pipelining and Composition, we used a proxy for getting operations in order to provide for automatic chaining. By using a proxy for setting and deleting operations, you may do your own freezing (if, instead of setting an object's property, you'd rather throw an exception). Implement a freezeByProxy(obj) function that will apply this idea to forbid all kinds of updates (adding, modifying, or deleting properties) for an object. Remember to work recursively, in case an object has other objects as properties!

10.2. Inserting into a list, persistently. In the Working with lists section, we described how an algorithm could add a new node to a list, but in a persistent way, by creating a new list as we earlier described. Implement an insertAfter(list, newKey, oldKey) function that will create a new list, but adding a new node with key newKey just after the node with key oldKey...