4 Pure, composable functions
This chapter covers
- Refactoring imperative coding to a declarative, functional style
- Understanding how to think functionally
- Master JavaScript’s higher-order functions
- Introducing pure functions and immutability
- Combining pure logic with curry and composition
- Improve readability and structure of your code with a point-free style
- Pipeline operator
“If you want to see which features will be in mainstream programming languages tomorrow, then take a look at functional programming languages today”
Simon Peyton Jones
If objects are the fabric of JavaScript, functions represent the needles that thread used to connect each piece together. We use functions in JavaScript to describe objects (remember classes are functions too) and also to move the machinery that advances the state of your application. The reason why functions are so ubiquitous, versatile, and powerful in JavaScript is because they are objects, too:
Function.prototype.__proto__.constructor === Object
JavaScript has higher-order or first-class functions—this means more power! So it’s in our best interest to take full advantage of them and this chapter teaches you how to wield this power through the functional programming paradigm.