Most of these examples use arrays and ignore objects. That causes the post to overlook quite a few advantages of underscore and lodash. For example, _.each() can take an object instead of an array. The first arg passed to the function is the value. The second is the key. Also, in lodash, returning false will end iteration early. It's like break in loops. These may seem like minor differences, but they allow for more flexible, powerful, and straightforward code.
And that's just one function. There are lots of similar nice-to-haves that make lodash and underscore worthwhile. Heck, I even use lodash for server-side stuff.
There's e.g. Object.keys(obj).forEach(...) and similar. _ is useful, but not always needed, especially if you care how many dependencies your project has. For a functional construct-heavy project, I'd choose Ramda.
I'll always choose Ramda. I find it much more intuitive and I feel like having data passed as the last parameter to functions allows for much more composable, clean code.
With lodash/fp you can be a cool kid whose apps don't hit critical perf issues or have to be rewrite for every minor upgrade. It's also cool to not have to wonder about support because fp is tested in browsers & node 😎
15
u/AngryParsley Jan 26 '16 edited Jan 26 '16
Most of these examples use arrays and ignore objects. That causes the post to overlook quite a few advantages of underscore and lodash. For example,
_.each()can take an object instead of an array. The first arg passed to the function is the value. The second is the key. Also, in lodash, returningfalsewill end iteration early. It's likebreakin loops. These may seem like minor differences, but they allow for more flexible, powerful, and straightforward code.And that's just one function. There are lots of similar nice-to-haves that make lodash and underscore worthwhile. Heck, I even use lodash for server-side stuff.
Edit: Fixed grammar.