Appendix C: Pointfree Utilities

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 -> Number
const add = curry((a, b) => a + b);

append

// append :: String -> String -> String
const append = flip(concat);

chain

// chain :: Monad m => (a -> m b) -> m a -> m b
const chain = curry((fn, m) => m.chain(fn));

concat

// concat :: String -> String -> String
const concat = curry((a, b) => a.concat(b));

eq

filter

flip

forEach

intercalate

join

last

map

match

prop

reduce

replace

reverse

safeHead

safeLast

safeProp

sequence

sortBy

split

take

toLowerCase

toString

toUpperCase

traverse

unsafePerformIO

Last updated