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

Composing and currying functions


The last section of this chapter is about assembling functions that realize larger behavior out of smaller functions. There are two ways to assemble such functions. The first is to use the appropriately named compose() function, which performs a nested invocation of the provided functions, or where order is important, we can use the flow() function to return values together. Currying lets you adapt your function to be called successively in different contexts. Each of these Lo-Dash tools lets you take the existing functionality in your application and build on it in interesting ways.

Composing functions

The compose() function builds a new function out of the provided functions. When we call this new function, a nested invocation of the supplied function starts, that is, the last supplied function is called with any additional arguments. The returned value is then fed to the next function and so on, ultimately producing a value for the caller. This is better...