concept function chain in category functional programming

appears as: function chains, A function chain
Functional Programming in JavaScript

This is an excerpt from Manning's book Functional Programming in JavaScript.

Listing 1.5. Programming with function chains
_.chain(enrollment)
  .filter(student => student.enrolled > 1)
  .pluck('grade')
  .average()
  .value(); //-> 90                                  #1

Now you can use Lodash to stitch together functions representing these steps, forming a functional chain, as shown in listing 1.5 (for a full explanation of what each of these functions does, you can visit the appendix for directions on where to find the proper documentation). A function chain is a lazy evaluated program, which means it defers its execution until needed. This benefits performance because you can avoid executing entire sequences of code that won’t be used anywhere else, saving precious CPU cycles. This effectively simulates the call-by-need behavior built into other functional languages.

Listing 1.5. Programming with function chains
_.chain(enrollment)
  .filter(student => student.enrolled > 1)
  .pluck('grade')
  .average()
  .value(); //-> 90                                  #1

Lodash uses the underscore convention because it began as a fork of the famous and widely used Underscore.js project (http://underscorejs.org/). Lodash still tracks Underscore’s API closely, to the point that it can serve as a drop-in replacement. But behind the scenes, it’s a complete rewrite in favor of more elegant ways to build function chains, as well as some performance enhancements that you’ll learn about in chapter 7.