In this appendix, you'll find pointfree versions of rather classic JavaScript functions described in the book. All of the following functions are seemingly available in exercises, as part of the global context. Keep in mind that these implementations may not be the fastest or the most efficient implementation out there; they solely serve an educational purpose.
In order to find functions that are more production-ready, have a peek at ramda, lodash, or folktale.
Note that functions refer to the curry & compose functions defined in Appendix A
add
// add :: Number -> Number -> Numberconstadd=curry((a, b) => a + b);
// sequence :: (Applicative f, Traversable t) => (a -> f a) -> t (f a) -> f (t a)constsequence=curry((of, f) =>f.sequence(of));
sortBy
// sortBy :: Ord b => (a -> b) -> [a] -> [a]constsortBy=curry((fn, xs) =>xs.sort((a, b) => {if (fn(a) ===fn(b)) {return0; }returnfn(a) >fn(b) ?1:-1;}));