Higher-Order Functions in JavaScript
eloquentjavascript.net
eloquentjavascript.net
I'd have to say that this book was one of the more gentle and concise introductory books I've ever read and so far I couldn't be happier that it was my personal introduction to JS and programming. It certainly set me leaps ahead in the JS section when I attended a web dev bootcamp. It is my personal go to for any of my friends who approach me about their interest in getting started with programming. Big Nerd Ranch books are a close second but I've only recently found them and begun reading them.
[1] - http://lodash.com/docs
With that new-found knowledge, I decided to make my 4th or 5th attempt at trying to grasp clojure and ran through some 4clojure problems. This time I breezed through the problems, and in many cases enjoyed writing it more than I would have in a typical iterative style. I made sure to follow some recommended users to see their solutions as well, which helped reduce much of my parentheses bloat.
My favorite thing about using high order functions has been that provided your underlying functions are tested/correct, you can more easily reason about and test your new functions, particularly when you keep things immutable/side-effect free.
I'm sure I would have gotten to this point eventually without Lodash, but being able to make use of bits and pieces at a time was a major catalyst for me.
I haven't tried it, but it looks like it could basically replace Ramda (although I feel that Ramda might contain even more FP oriented functions).
My library of choice is http://www.preludels.com
I started writing a comparison between un-sugared JS and LS use for functional programming patterns, here: https://klibert.pl/warsawjs-talk/code.html (for the talk I gave: https://klibert.pl/warsawjs-talk/).
That being said, I'm very interested in mori, immutable-js or lz.js. prelude-ls is nice, but is designed to work with native JS types and provides no extended semantics that I'd find useful. It's still my go-to library when working on the frontend and it probably will remain one, but I'm thinking about contributing some support for other advanced collection types to it.
The optimal functional utility library would be designed with autocurrying in mind from the start, but not shy away from flexibility where it makes sense.
lodash-fp does this for max, min, & uniq by offering maxBy, minBy, & uniqBy.
[1] - http://www.cse.chalmers.se/~rjmh/Papers/whyfp.pdf
[2] - http://shop.oreilly.com/product/0636920028857.do
[3] - http://stackoverflow.com/questions/36504/why-functional-lang...
[4] - http://scott.sauyet.com/Javascript/Talk/2014/01/FuncProgTalk...
> console.log(sum(range(1, 10)));
> Which one is more likely to contain a bug?
I'd say the second one. Because the first one is totally transparent. The second one relies on functions I can't see. Especially the "range" function may cause problems because here it generates the full range, including both delimiters, unlike the range function in e.g. python.
EDIT: functional programming is extremely useful, but I don't think this example really highlights the most important advantages.
There are certainly times when you need to see the implementation details or that your needs don't fit the prescribed and available functions (eg, range being exclusive vs inclusive), but then if that is the exception rather than the rule, it will serve as another indicator when you come across that code that `this is doing something different than usual`, so pay attention to the details.
But then Python beat me into submission with its seductive collection comprehension... Now I see it as a standard convention, like indexing should start with 0.
If you understand mostly what everything else is in a system, then people basically swarm around the behavior of something undefined in order to fuzzily define it. It sticks and it does not stick - it depends on whether programmers rewrite the system or the word is forgotten about on some super secure layer of abstraction, or whether it's the word that everyone is teaching and talking about and naming things after.
I don't think words can really express this process, it's pervasive and paradoxical to it's description. You have to assume you understand everything else, before you can label something truly new. Otherwise it's just the same amorphous blob, and the labels keep swapping, and no concepts are really applicable, because they are only observable from a macroscopic perspective of abstraction, except when they are being used, right there in front of the code. It's always the same balance of 'i know some stuff' and 'i don't know some stuff'.
More importantly, your solution doesn't scale to more complex abstractions, or to more complex properties, such as whether it is thread-safe or what exceptions it could throw. Plenty of bugs result from mistaken assumptions about such things, or simply by overlooking them.
To compose iterables, you'd presumably work with iterators directly instead of the sugar.