-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
_.chunk or _.stride function #1891
Comments
In my implementation I opt'ed for not supporting a "remainder" function as Underscore and the like have sided on not destroying data when possible. |
Seems reasonable. I can't actually think of any situation where this would outright break anything. |
@jdalton Could you post a link to the function in the edge source? |
FYI, we have |
@joshuacc I feel like their implementation for Since both implementations are in contrib the need for a "remainder" option seems useful, however, it shouldn't truncate the remainder by default, in my opinion. Having it as an optional boolean also means it would require less code to switch between modes in conditional situations; Requiring only an expression versus being wrapped in an if statement. |
See my comment on issue #1890. Not dropping remainders by default also allows adding an option in at a later time if the request is popular enough. |
@Soviut Yeah. I don't have any objections to keeping remainders by default. Just wanted to make sure folks in this thread were aware of contrib's current implementation when discussing the proposal. If this makes it into Underscore, then we'll revise contrib to play nicely with it. 😄 |
See #696. I don't think this will be accepted, and if it was I'd much rather see |
A common function I'm sure many of us run into (especially regarding pagination) is the need to break an array into chunks of a specified length. I propose a
_.chunk()
(or_.stride
if "chunk" isn't clear enough). It would also be useful in a number of other underscore features, including my proposal for_.objects
#1890.The first value would be the list, the second value would be the chunk-size/stride-length. If the chunk size doesn't divide evenly into the length of the list, the final item should be the remainder.
Would yield
It might be worth having an optional "remainder" boolean argument that could omit the remainder if set to false, but should probably be true by default. This would be useful in cases where the chunks were going to be mapped using
_.object
and dangling arguments weren't desirable.Would yield
The text was updated successfully, but these errors were encountered: