Article originally published on Hello.js
As a Perl coder, I'm a big fan of functional programming.
If that sounds odd to you, think about all that features that are considered as idiomatic Perl :
- List processing (map, grep)
- High order functions (Mark Jason Dominus ;-) )
- Lazy evaluation (iterators)
- Lamda calculus (closure)
Functional programming is a fascinating thing but it’s not so easy to use consistently. We all love the concept, feel the inner power. We all use lists, closure, functions as parameter, but how many of us manage to fully apply functional programming everywhere and commit to pure functions and immutability ?
There are several other functional programming libraries (more on that below) but what makes Ramda so practical and somewhat unique is its combination of auto-currying and the design choice to put the data last. These two things empower you and give you endless possibilities through composition.
You probably already know how map and grep can compose to solve many different tasks in a clean way. Now imagine that Ramda offers you one hundred of such functions. The number of combinations, solutions and tasks that you can solve easily just explodes! *1
This might seem theoretical, but for a simple demonstration of how Ramda can ease your life, just read “Why Ramda ?” by Scott Sauyet.
Among the other things that make Ramda so powerful, Iis its ability to mix with promises through ‘pipeP’ and ‘composeP’. Being able to use both functional programing and promises through a clean syntax is priceless to me.
I should also underline the fact that Ramda promotes immutability: it doesn’t mutate input data by default but still allows you to produce modified one through 'assoc'.
As a final note: Don’t be scared by Ramda’s API, it offers probably far more than you want, but everything you need. Follow the easy path: just pick/learn functions one by one.
The well known 'generic' libraries offer functional tools, like the venerable underscore, lodash and it’s speedy brother lazy to name a few.
The reactive programming world also provide functional features with RxJs, Kefir or Bacon for the UI.
And if you want to experiment immutability, the choice is your : You can climb on the shoulders of a giant and use Facebook’s immutable or favour speed with mori or try the frozen object approach of icepick.
Oh, and if you wonder about the title:
I like Ramda so much that I wanted to use it in my daily work, and started to write a port in Perl: Pramda (Perl Ramda). Any resemblance to any film title is purely coincidental...