The Silence: Review

In notebook:
FrontEndMasters Hardcore Functional
Created at:
Functional Programming JavaScript
recognise most loops are one of
  • reduce
  • map
  • filter
​each​ is not pure, has side effects. 
You should never use loops! 

In review...

  1. Make all functions inputs explicit as arguments (separate from environment)
  2. These arguments can be provided over time, not just all at once
  3. Try not to modify outside things (or keep it very localised, like updating the DOM)
  4. Compose without "glue" variables
One of the benefits of ​compose​ is that you don't need to name things. More composition demos. 

Taking the articles model:
  var articles = [
    title: 'Everything Sucks',
    url: 'http://do.wn/sucks.html',
    author: {
      name: 'Debbie Downer',
      email: 'debbie@do.wn'
    title: 'If You Please',
    url: '',
    author: {
      name: 'Caspar Milquetoast',
      email: ''
Take one article and show its title. 
  _.compose(_.get('title', _.take(1)))(articles)
Then to get the title
  _.compose(get('title'), _.head)(articles)

So you get the same thing as: ​articles[0].title

The functional solution is much more flexible. You can easily add ​null​ checks, etc. As compared to articles[0].title. Here, you would need to do null checks, and you're stuck with this data structure. In the functional programming style, you can lift these value into these containers (more about them later) and don't worry about null checks.

The problem with underscore or lodash is that their utility functions don't have the arguments in the right order to be curried.