casualjavascript / haskell-in-es6

Source for "Haskell in ES6" article series

Home Page:http://casualjavascript.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Quick notes

roman01la opened this issue · comments

Hello, just some quick notes I've took while reading the article with code samples. I could be wrong somewhere, but here they are:

  • In ES6 you can use spread operator to apply an array to a function as a list of separate arguments. So, instead of f.apply(null, args), you can do f(...args).
  • In comp example functions are executed left to right, but it's common for composition to execute functions in the opposite direction, which is right to left.
  • Also comp function could be written in more elegant way, using reduce.
  • flip could be just (f) => (...args) => f(...args.reverse()).
  • head is (x, ...xs) => x.
  • tail is just (x, ...xs) => xs.

The benefit of using rest parameter operator for head and tail is that it's using Iterator protocol which means that any data structure that implements this protocol can be applied with those functions.