For the past year plus, my colleague Scott Sauyet and I have been working in our free time on Ramda,
“a practical functional library for Javascript programmers.” When we signed up for Frontend Masters
“Hardcore Functional Programming with Javascript” workshop, we were surprised to learn that they had selected
Ramda to illustrate their examples. With that vote of confidence, we figured it is time to announce the arrival of
Ramda.
There are already some excellent libraries with a functional flavor, such as
Underscore and Lodash.
Ramda includes all of the favorite list-manipulation functions you expect, e.g. map, filter, reduce, find,
etc. But Ramda is significantly different from libraries like Underscore and Lodash. The primary distinguishing features of Ramda are:
Ramda takes the function first, and the data last.Brian Lonsdorf explains why this parameter ordering is a big deal.
In a nutshell, the combination of currying and function-first enables the developer to compose functions with very
little code (often in a “point-free” fashion), before finally passing in the data. So instead of this:
… you can do this:
Ramda methods are automatically curried. While you can curry (or partially apply) functions in Underscore and Lodash, Ramda does it for you. Virtually all methods of 2 or more arguments are curried by default in Ramda. For example:
This auto-currying makes it easy to compose functions to create new functions. Because the API
is function-first, data-last, you can continue composing and composing until you build up the
function you need before dropping in the data. (Hugh Jackson published an excellent article
describing the advantages of this style.)