javascript - Differences between Lodash and Ramda - Stack Overflow
Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
Explore Stack Internal
Differences between Lodash and Ramda
Ask Question
Asked<br>4 years, 3 months ago
Modified<br>4 years, 3 months ago
Viewed<br>19k times
37
So I've been researching a little bit about JS frameworks. From what I saw, two of the most popular and modern libraries are Lodash and Ramda (right?).
I saw a similar question regarding Lodash and Underscore. However, I didn't see anything related to Lodash and Ramda. Also I couldn't find any benchmark to be honest.
What are the differences? How about the use cases? Which one is better?
javascript<br>lodash<br>ramda.js
Share
Improve this question
Follow
asked Mar 8, 2022 at 21:07
Jose Andrés
53311 gold badge55 silver badges77 bronze badges
Add a comment
1 Answer 1
Sorted by:
Reset to default
Highest score (default)
Trending (recent votes count more)
Date modified (newest first)
Date created (oldest first)
106
Dislaimer : I'm one of the founders and chief maintainers of Ramda, so I'm sure this answer will include some personal bias. I'll try hard not to let it get out of hand.
Overview
As to this part of the question:
Which one is better?
There is no way anyone here can answer that definitively. It depends on your requirements, your history, your programming taste, and a million even more fuzzy factors.
I'm biased in favor of Ramda, of course, but I still won't try to tell you which one is better.
But there are significant overlaps in capability between these two and significant differences in underlying philosophy.
Both are grab-bags of utility function, with little or no cohesion between the functions. That is, they are libraries and not frameworks. They don't at all try to determine how you write or organize your code.
They have a great deal of overlap. Among the 305 current lodash functions and the 261 current Ramda ones, there are 103 with shared names, and almost always, similar purpose. Probably half the remaining functions are found in the other library under different names.
A Brief History
Although there were some experimental functional libraries before it, Underscore was the one that brought many of these concepts to the mainstream of Javascript. It stood alone for a while as the undisputed leader in this space.
But there were problems with its performance. Eventually lodash was created in large part to try to do the same thing with better performance. By creating custom versions of classic functions like map, rather than defaulting to the JS engine's built-in ones, lodash was quickly able to outperform Underscore. But it started as a drop-in replacement for Underscore, and kept that focus for a long while.
The Ramda founders were impressed with the ideas in Reginald Braithwaite's JavaScript Allongé and created Ramda as an educational tool to help turn these ideas into a pragmatic library. They were less focused on performance, and more on a clean API and functional composition, as well as immutable data and side-effect-free coding. Through an odd series of events, it eventually grew quite popular.
These days you don't hear much about Underscore. It's still out there, and still used a fair bit, but you don't hear much buzz. For most users, lodash fills that space well. Ramda grew quickly, but seems to have settled down at about 20 - 25% of the downloads that lodash gets. But all three libraries continue to grow in capability and in usage, with Underscore and Ramda about the same usage, far below lodash.
At one point, lodash created a version that tries to take into account some of Ramda's core concerns. I personally have never used lodash-fp so I can't speak to how successfully it does this.
Philosophy
lodash
Lodash focuses on flexibility and performance. Its focus, as its creator once described, is on
providing quality utility methods to as many devs as possible with a focus on consistency, compatibility, customization, and performance.
While no general-purpose library can ever be quite as fast as custom-written code, lodash gets as close as possible.
And lodash is flexible. I wrote several years ago
Consider lodash's filter: It accepts an array, object, or string for its collection, a function, object, string, or nothing at all for its callback, and an object or nothing at all for its thisArg. You're getting 3 * 4 * 2 = 24 functions in one!
Ramda
Ramda is less concerned with performance, and more with simple and clean API design. The idea for Ramda is that a function should do one thing only, and should have a single clear interface. Ramda's filter function takes a predicate function and an object of a filterable type, and returns another object of that type. (Of course this...