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 functions


Whether our functions are called manually, used as a callback by another function, or used in some other context that involves chains, function composition helps construct larger pieces of functionality. For example, we may have two smaller functions that serve niche purposes on their own. When we're in scenarios where these functions may come in handy, we can use the functional tools in Lo-Dash to compose a new function that utilizes them, rather than roll out our own.

Composing generic functions

Earlier in the chapter, we emphasized the idea that functions need to be generic if they're to be of any service in more than one context. The same idea holds true when composing larger components of smaller functions. The smaller functions need to be generic if we're going to use them to compose anything larger. Likewise, the composite should also be as generic as possible so that we can use it as an ingredient in a larger piece of the application. This is shown in the following...