7 ms·
Lodash v3.0.0
- mackwic 12y agoAlready submitted: https://hn.algolia.com/?query=lodash&sort=byPopularity&prefix&page=0&dateRange=last24h&type=story https://hn.algolia.com/?query=lodash&sort=byPopularity&prefi... Seems like no one cares. Strange.
- Turing_Machine 12y agoIt's easy to not care when there's no context or indication as to what Lodash might be. Too many links, not enough time. I did click -- but only because a previous comment made it seem like Lodash was something related to functional programming. If it hadn't been for that comment, I have ignored the post, because I wouldn't have had a clue WTH Lodash was. Now, sure, people who've already used or heard of Lodash are going to know, but they're probably already following it on Github. :-) The unwashed masses like me won't have any idea. I guess the key here is to try to make the title give some indication of what the thing is.
- weavie 12y agoThere are two kinds of JS developers, those that use LoDash at least once per function and those that have never heard of it!
- arcatek 12y agoI use Lodash but i see not point in this announcement in its current form - what changed exactly? [edit] Changelog is there https://github.com/lodash/lodash/wiki/Changelog https://github.com/lodash/lodash/wiki/Changelog Some decisions sound really weird, such as the fact that forEach is now lazy. It is not a standard replacement anymore, and probably break the compatibility for quite a few apps (even if I'm deeply convinced that we should all use the native functions and shim them when needed).
- woah 12y agoAre you talking about this? // in 2.4.1 _([1, 2, 3]).forEach(function(n) { console.log(n); }); // => logs each value from left to right and returns the lodash wrapper // in 3.0.0 _([1, 2, 3]).forEach(function(n) { console.log(n); }); // => returns the lodash wrapper without logging until `value` is called _([1, 2, 3]).forEach(function(n) { console.log(n); }).value(); // => logs each value from left to right and returns the array Seems that the only apps this change will break are those who are using side effects in a chain. Which is a pretty dubious choice, IMO. Especially given that Lodash is a "functional programming library".
- jkrems 12y agoIt's only lazy when using the chaining syntax - and that one was never a standard replacement since `_.map(arr, fn)` returns a wrapper around a value and not a value.
- olivierkaisin 12y agoSee release notes and changelog: - https://github.com/lodash/lodash/releases/tag/3.0.0 https://github.com/lodash/lodash/releases/tag/3.0.0 - https://github.com/lodash/lodash/wiki/Changelog https://github.com/lodash/lodash/wiki/Changelog
- riquito 12y agoThanks for the link, I was expecting a CHANGELOG file in the project.
- bsimpson 12y agoI dig laziness, but why is `forEach` lazy? That's the only one that invokes immediately in libraries like Lazy.js.
- quadratini 12y agoIt's only lazy if it's part of a chain
- jdd 12y agoChaining is deferred until `value()` is implicitly or explicitly called. However shortcut fusion does not apply to `forEach`.
- tobr 12y agoReally nice to see that there's now an auto-curried, function-first version, lodash-fp! I've been really attracted by Ramda JS recently for this reason. https://www.npmjs.com/package/lodash-fp https://www.npmjs.com/package/lodash-fp
- rikkus 12y agoI've been looking for some real-world examples of how currying might be useful in javascript. Haven't not used a language which supports currying for any real world project, I'm interested to know how it can help. I found a page [1] which talks about currying in javascript, then says "Are there practical uses for currying in JavaScript? Not really." Can you point me at anything which will help me see why it's useful? [1] http://benalman.com/news/2012/09/partial-application-in-javascript/ http://benalman.com/news/2012/09/partial-application-in-java...
- ilitirit 12y agoSome code that I've written using Ramda.js: var predicateListFunc = function(props) { return R.allPredicates(R.map(R.curry(R.eqProps), props)); } var compareProperties = R.unapply(predicateListFunc); var mergeLists = R.unionWith(compareProperties("Property1", "Property2")); var groupById = R.groupBy(R.prop("Property1")); var getGroups = R.compose(R.toPairs, groupById, mergeLists); var groups = getGroups(list1, list2); With this code I can merge any two lists (list1 and list2) on any two properties (Property1 and Property2), and then group the result. I use this to synchronize client and server data. I don't know if this answers your question, since I wrote in about an hour of learning Ramda.js, and there might be an easier way of doing it. Here's a fiddle: http://jsfiddle.net/Gk6uu/10/ http://jsfiddle.net/Gk6uu/10/
- jmcmichael 12y ago"A programmer’s pipe-dream is to write code, and be able to use it repeatedly with little effort. It’s expressive because you write in a way that expresses what is needed, and it’s reuse because.. well, you’re reusing. What more could you want? Curry can help.": http://hughfdjackson.com/javascript/why-curry-helps/ http://hughfdjackson.com/javascript/why-curry-helps/
- allendoerfer 12y agoThe lodash & lodash-compat npm packages now come with modules baked in too. Perfect for Browserify! // load the modern build var _ = require('lodash'); // or a method category var array = require('lodash/array'); // or a method var chunk = require('lodash/array/chunk'); This is great. It combines trust and quality with modularity.
- facepalm 12y agoIs this the same as underscore.js?
- msl09 12y agohttp://stackoverflow.com/questions/13789618/differences-between-lodash-and-underscore http://stackoverflow.com/questions/13789618/differences-betw...
- facepalm 12y agoThanks - it sounds as if you could use it as a drop in replacement for underscore.
- Pephers 12y agoYes, you can. I've successfully done so in a Backbone/React app. The _.chain() method furthermore gives a nice functional style ways of building lists which is useful when building UI in React, like so: var list = _.chain([1, 2, 3, 4, 5]) .filter(function (value) { return value > 2; }) .map(function (value) { return value; }); console.log(list); // prints: // [3, 4, 5]
- masklinn 12y agoThat's not "furthermore". chain/value also exists in underscore. Also your code was broken in Lodash 2 (it'd return a lodash object, not a list) and is more broken in Lodash 3 (chains are now lazy), so your code does just about nothing until you force the iterator's evaluation)
- jdd 12y agolodash v2 offers an Underscore build that aligns its chaining and other API with Underscore providing a full drop-in replacement. However because lodash is a superset of Underscore those using the Underscore build lose out on additional methods, optimizations, & cross environment fixes. Over the last year Underscore has align more & more with lodash’s API so the need for a separate Underscore build has diminished. If you still need compatibility around some of the edges you should leverage modules in lodash v3 to supplement your Underscore use until the time you can drop Underscore completely.
- urza 12y agoIt is alternative to underscore.js? Or extensions for underscore.js? Not clear from the page...
- woah 12y agoIt's supposed to be better, faster, and stronger (more functions) than underscore. It's also under active maintenance from an enthusiastic dev. Do your own research, but I go with lodash.
- jsprogrammer 12y agoLazy.js claims to be even faster than both with support for lazy evaluation to boot. Not quite a drop-in replacement like lodash is, but I think it only requires a minor tweak.
- d4n3 12y agoseems like lodash now has lazy evaluation as well when using the _(obj).method() syntax: http://filimanjaro.com/blog/2014/introducing-lazy-evaluation/ http://filimanjaro.com/blog/2014/introducing-lazy-evaluation...
- killercup 12y agoA new feature in 3.0 is that lodash now supports lazy evaluation using the chaining API from 2.x.
- masklinn 12y agoSo 2.0 code which used chaining is now broken if it doesn't explicitly exhaust the chain?
- je42 12y agoLazy.js is however not that active. I guess the community around it still needs to develop.
- astalwick 12y agoWe switched from underscore to lodash several months ago, and haven't regretted it. The fact that lodash follows semver is huge. Underscore has introduced serious breaking changes in minor point-releases more than once, which is completely unacceptable for a utility library.
- Elrac 12y agoI followed the link and saw "lodash" for the first time today. Oh, it's a library! With an API! In various formats! I always appreciate it when the top of the project page provides a one-liner explaining just what it is I'm looking at.
- aikah 12y agoYeah,the doc sucks a bit because you're supposed to know it's a "fork" of underscore. They could do a better job at explaining why lodash is useful, because it definetly is.It can really reduce the amount of js code one is writing by 2 or 3. In a nutshell it's a collection of functions that work on arrays,objects and functions.It's a toolbox.
- falcolas 12y agoI wish that it had mentioned what it was a library for. Took me longer than it should have to identify that it was a Javascript library. I probably should have guessed, but I hate guessing wrong and missing out on something I could really use.
- listic 12y agoYep, one might think that one could manage a decent description by version 3.0.0
- jdd 12y agolol, added "JavaScript" to the description :)
- ecaron 12y agoThe changelog at https://github.com/lodash/lodash/wiki/Changelog https://github.com/lodash/lodash/wiki/Changelog gives some nice examples of breaking changes for anyone moving from v2.x
- deleted 12y ago[deleted]
- Sarien 12y agoQ: "What does it do?" A: "A utility library delivering consistency, modularity, performance, & extras." Q: "Yeah, but what does it do?" A: "Oh, nothing but it does it consistently, modularly and performant. We also have functions for string handling in the extras module."
- nailer 12y agoIt's extra stuff that should be in the standard library but isn't. These days, a lot of it is actually in the standard library - for example, array maps - and invoking lodash just calls the es5/es6 built in, with a slightly uglier syntax.
- aliem 12y agoThe most important feature is chaining and lazy evaluation. I think the most useful functions are the typechecking utilities (typeof in javascript is the most useless keyword the human kind engineered in a language). In the end is a very nice library to work with when it does not get in the way (of course, if you are using `_.each([], fn)`, you should think again and use `Array#forEach` or a nice `for`)
- M2Ys4U 12y ago>of course, if you are using `_.each([], fn)`, you should think again and use `Array#forEach` or a nice `for` You probably shouldn't if you're in a hot path. LoDash actually outperforms some native ES5 features, Array#forEach being one of them IIRC.
- acjohnson55 12y agoBut if you want backward compatibility, you still probably want to use something like Lodash. I'd also argue that Lodash's/Underscore's interface is far better thought out than the standard library. The standard library has so many absurd gotchas, like `["2", "2", "2", "2"].map(parseInt)`. The verbosity of Javascripts lambdas also makes composition of simple parts more arcane looking than necessary, and having a whole bunch of composable/chainable utility functions does a lot to help people write self-documenting code.
- jtheory 12y agoWhoah: "Tested in Chrome 39-40, Firefox 34-35, IE 6-11, Opera 25-26, Safari 5-8"... IE6+ support! I wonder if that's real, full support, or more like a "there are serious bugs we'll probably never fix for old IE". Working with old IE versions is loathsome (but still required for some of us), so libraries that just work there are much appreciated.
- jdd 12y agoYap it's tested in IE6 & full support. https://saucelabs.com/u/lodash https://saucelabs.com/u/lodash
- edwardg 12y agoFor anyone interested in learning more about lodash, Adam Boduch's "Lodash Essentials" book just got released, and covers everything in v3 (he delayed it to make sure it covered v3). https://www.packtpub.com/web-development/lo-dash-essentials https://www.packtpub.com/web-development/lo-dash-essentials
- acjohnson55 12y agoLodash is an incredible accomplishment, and having it vastly improves the Javascript authorship process over the standard library. That being said, I still can't believe we don't have a flatMap: https://github.com/lodash/lodash/issues/812 https://github.com/lodash/lodash/issues/812 https://github.com/jashkenas/underscore/issues/452 https://github.com/jashkenas/underscore/issues/452 (Underscore repo, but still Mr. Dalton, author of Lodash, opposing.)
- invisible 12y agoHe explained how to add a flatMap in 2 lines in the first linked issue. It sounds pretty trivial to add per app.
- sosuke 12y agoSo going modern means breaking in PhantomJS, that is a bummer.
- jdd 12y agoIt doesn't mean it's breaking in PhantomJS. The modern build lacks some iteration fixes for older environments is all. In the case of PhantomJS it's edge iteration of things like `arguments` objects. The modern build won't error out even in IE6.
- sgrove 12y agoI've been playing around with getting Mori[0] more js-like, from more idiomatic function names and argument order (fn as the last argument, released) to playing around with a chaining API. Ideally we should be able to wrap javascript values, manipulate via idiomatic chaining (similar to Lodash), while getting most of the benefits from highly-tuned persistent data structures, lazy sequences, etc. e.g. expect(_([1,1,1,1,2,2,3,4,5,6,6]).distinct().conj(7).out()).toEqual([1,2,3,4,5,6,7]); Here's a small set of specs showing early ideas https://github.com/swannodette/mori/blob/8e82b15b35b2989d4a2d5d74c6a23f5bf779ea2f/spec/chain-spec.js https://github.com/swannodette/mori/blob/8e82b15b35b2989d4a2... [0] https://github.com/swannodette/mori https://github.com/swannodette/mori
- andrezsanchez 12y agoI've tended to avoid both underscore and lodash because they're both in the slew of monolithic pre-npm libraries, however the lazy evaluation looks interesting. I wouldn't be surprised to find a library that handles lazy eval without all the extra features Lodash brings.
- jgalt212 12y agoFor the shops who don't live and breath js and whose js work is almost entirely browser-based, these monoliths are great. I, for one, am bummed that the js market is moving away from monoliths. e.g. YUI shutting down.
- andrezsanchez 12y agoThat's an interesting perspective. I don't have any inherent problems with large libraries, but my problem with some of these 'monoliths' is that other libraries start to depend on the entire library when they only need a small piece of functionality that the library provides. Substack wrote an article [1] explaining some of the problems that monolithic libraries cause in an ecosystem. [1] http://substack.net/many_things http://substack.net/many_things
- jgalt212 12y agothanks, I'll check that out.
- acjohnson55 12y agoThere is lazy.js (http://danieltao.com/lazy.js/ http://danieltao.com/lazy.js/). Also, lodash is highly factored into pieces if you don't want the whole thing.
- WickyNilliams 12y agoWith browserify (or webpack) you can require just the functions you want, and only those (and their dependencies) end up in your code base. This is covered in the changelog
- 12y ago
- tieTYT 12y agoIt's not clear to me: Is that list at the bottom new things in v.3?
- picardo 12y agoIs there build of this that lets me require a single function?
- insin 12y agoEvery function is published to npm as a module: https://www.npmjs.com/browse/keyword/lodash-modularized https://www.npmjs.com/browse/keyword/lodash-modularized