Ramda – A practical functional library for Javascript
ramda.github.io
ramda.github.io
I'm joking (kind of), but I was reminded of this talk about implementing TeX in Clojure [0], in which you are shown the pains Don Knuth took to avoid subroutines calls, ostensibly for performance reasons—such heavy macro usage, for example, that the speaker calls the language a "dialect" of Pascal. Now we have the maxim about programmer cycles versus machine cycles, which is itself getting a little dated because of scale.
Anyway, fun times to be in this field. You might also like the "It's 1982 and I can't believe we're still..." part of the talk, (a.k.a. "Everything's amazing and nobody's happy") for putting things into perspective.
[0] https://www.youtube.com/watch?v=824yVKUPFjU
EDIT Time is on their side though... with tail-call optimization coming to ES6 (just about the only "good part," according to Crockford).
The build-in currying of most of the methods is pretty cool as well.
For me, it's difficult to break away from using the built-ins such as Array.prototype.map/reduce etc in favor of more functional variants. The same goes for Immutables... I see the value in adjusting the code in terms of explicitness, it's still hard to get used to.
--edit
Is there something built-in to apply all the functions into the current global? I'd rather not have to do...
var R = require('ramda');
var propEq = R.use(R.pipe).over(R.get, R.eq);
over... require('ramda').assignTo(this);
var propEq = use(pipe).over(get, eq); var R = require('ramda');
with (R) {
var propEq = use(pipe).over(get, eq);
}
...Or even: var R = require('ramda');
for (var f in R) {
window[f] = R.f;
} var R = require('ramda');
for (var fn in R) if (typeof R[fn] === 'function') global[fn] = R[fn]; { use, pipe, get, eq } = R
propEq = use(pipe).over(get, eq)yes: `R.installTo(global)` will pull all of the ramda functions on the `global` object
He does not focus on Ramda (or any library per se), but he uses and explain several of it's functions to illustrate how simple it is to use functional programming concepts and achieve a code with much more quality and readability.
Definitely a must read for those adventuring in this world :)
http://scott.sauyet.com/Javascript/Talk/2014/01/FuncProgTalk...
You can boil down FP on JS to 5 fundamental functions:
* map
* reduce
* filter
* compose
* curry
* forEach (maybe)
the first 3 and last 1 are already available to you on arrays. Compose is a pretty simple polyfill as is curry, I'm not sure if you really need an entire library to add this in for you.
Thanks, authors!
var where = _(_.where).rearg(1,0).curry().value();