Book Image

Lo-Dash Essentials

By : Adam Boduch
Book Image

Lo-Dash Essentials

By: Adam Boduch

Overview of this book

Table of Contents (15 chapters)
Lo-Dash Essentials
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Map/reduce patterns


We'll close the chapter with an introduction to some basic map/reduce patterns, applicable to everything you've learned in this chapter so far. First, we'll take a look at what generic callback functions look like and why they're useful. Then we'll introduce the notion of map/reduce chains.

Generic callback functions

As the development of your frontend application progresses, you'll start to notice that there is some commonality between all of your map/reduce callback functions. In other words, you could probably factor the generic aspects of the callbacks into a single generic callback. As you've seen throughout this chapter and the previous chapter, it's easy to partially apply and compose new functions with Lo-Dash. This is especially helpful when you have a handful of generic functions that you'd like to use as callbacks.

For instance, let's create some generic map() callback functions and see how they can be used:

function add(item) {
    var result = _.clone(item);...