Quick notes
roman01la opened this issue · 0 comments
roman01la commented
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 dof(...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, usingreduce
. 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.