Book Image

Mastering Immutable.js

By : Adam Boduch
Book Image

Mastering Immutable.js

By: Adam Boduch

Overview of this book

Immutable.js is a JavaScript library that will improve the robustness and dependability of your larger JavaScript projects. All aspects of the Immutable.js framework are covered in this book, and common JavaScript situations are examined in a hands-on way so that you gain practical experience using Immutable.js that you can apply across your own JavaScript projects. The key to building robust JavaScript applications using immutability is to control how data flows through your application, and how the side-effects of these flows are managed. Many problems that are difficult to pinpoint in large codebases stem from data that’s been mutated where it shouldn’t have been. With immutable data, you rule out an entire class of bugs. Mastering Immutable.js takes a practical, hands-on approach throughout, and shows you the ins and outs of the Immutable.js framework so that you can confidently build successful and dependable JavaScript projects.
Table of Contents (23 chapters)
Title Page
Credits
About the Author
About the Reviewer
www.PacktPub.com
Customer Feedback
Preface

Reducing collections


When you map collections, you always end up with the same type of collection with the same number of values. When you iterate over every value in the collection and produce something that's not a mapped collection, it's called a reduction. Filtering is a type of reduction, for example, but sometimes, you need to produce noncollection values from collections.

When filtering isn't enough

If you need to produce another collection, combining filter() and map() is usually the right answer. You can compose your filter() and map() calls using concise and easy to read iteratee functions. When you need to produce a simple value, the reduce() method is there for you.

Note

Manually reducing collections using reduce() requires more implementation effort than either map() and filter(), which is why you should avoid it where possible. Another reason to avoid it is that it can't be executed lazily in a sequence.

Producing minimums and maximums

An example of where mapping and filtering collections...