You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I realize that underscore has been around for awhile, is widely used, and as such won't be changing its basic chaining approach anytime soon. Despite that, I think that the current chaining model is needlessly verbose, which is why I think it'd be great if there was an option (either a plug-in or some sort of Underscore setting) that allowed the following alternative chain syntax:
(foo).operation1().operation2().;
In other words, this plug-in would:
Change the _(foo) usage of underscore to imply a .chain() call
When in "chained" mode, underscore would give the return value of any function an "" property, which would be set to the same value that would have been returned had the function not been in "chained" mode
(This doesn't really have to be ""; it could be "$" or "v" or "val" or ... you get the idea; I just thought using underscore for this value seemed appropriate, and it gives the whole line a nice symmetry, as it starts and ends with an underscore).
Of course, you could make the argument that if one is doing enough operations to justify chaining (3+ for me, but I'm sure others have different thresholds), the extra .chain() and .value() aren't a huge deal. And they aren't ... but just because something isn't a huge deal doesn't mean it can't be improved :-) I use underscore chaining fairly often (a testament to how useful the library is), and even a minor reduction in verbosity would have a noticeable effect on my code.
The text was updated successfully, but these errors were encountered:
I realize that underscore has been around for awhile, is widely used, and as such won't be changing its basic chaining approach anytime soon. Despite that, I think that the current chaining model is needlessly verbose, which is why I think it'd be great if there was an option (either a plug-in or some sort of Underscore setting) that allowed the following alternative chain syntax:
(foo).operation1().operation2().;
In other words, this plug-in would:
(This doesn't really have to be ""; it could be "$" or "v" or "val" or ... you get the idea; I just thought using underscore for this value seemed appropriate, and it gives the whole line a nice symmetry, as it starts and ends with an underscore).
This alternate syntax would take code like this:
return _(foo).chain().pluck('bars').reduce(reducer, []).compact().value();
or:
return .compact(.reduce(reducer, _.pluck(foo, 'bars')));
and replace it with:
return (foo).pluck('bars').reduce(reducer, []).compact().;
which is both clearer and simpler.
Of course, you could make the argument that if one is doing enough operations to justify chaining (3+ for me, but I'm sure others have different thresholds), the extra .chain() and .value() aren't a huge deal. And they aren't ... but just because something isn't a huge deal doesn't mean it can't be improved :-) I use underscore chaining fairly often (a testament to how useful the library is), and even a minor reduction in verbosity would have a noticeable effect on my code.
The text was updated successfully, but these errors were encountered: