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
{{ message }}
Repository navigation
IEnumerable should have a extension for creating fixed size chunks #27449
There's currently no method available to create chunks from an IEnumerable<T>. It's a popular functionality as this comment shows.
I believe most projects in need of this functionality have their own extension to IEnumerable<T> and the goal of this proposal is to have System.Linq offer this functionality
Proposed API
namespace System.Linq
{
public static class Enumerable
{
+ public static IEnumerable<T[]> Chunk(this IEnumerable<T> source, int size);
}
public static class Queryable
{
+ public static IQueryable<T[]> Chunk(this IQueryable<T> source, int size);
}
}
Another way to create chunks would be to specify the amount of chunks you would like to have from an IEnumerable<T> but I think it would be more desirable to have it as a separate method.
like the sample below.
// Where size determines the split amount.publicstaticIEnumerable<T[]>SplitBy(thisIEnumerable<T>source,intsize){...}int[]numbers=newint[]{1,2,3,4,5,6,7,8,9,10}IEnumerable<int[]>numberChunks=numbers.SplitBy(2)// {[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]}
Risks
This could potentially be a breaking change for users who have their own extension methods due to naming collisions.
Reacted by Petr Onderka, Daniel Chalmers, Yuuki Wesp, Nathan Dykstra, GSPP, kronic, Marcus and Tan90909090
@inputfalken If you want to add a new API to .Net Core, you should follow the API review process. That means not opening a PR before the API is accepted and also including a speclet in this issue.
changed the title [-]IEnumerable should have a extension for creating chunks[/-][+]IEnumerable should have a extension for creating fixed size chunks[/+]on Sep 22, 2018
Activity
benaadams commentedon Sep 22, 2018
GroupBy?
svick commentedon Sep 22, 2018
@inputfalken If you want to add a new API to .Net Core, you should follow the API review process. That means not opening a PR before the API is accepted and also including a speclet in this issue.
inputfalken commentedon Sep 22, 2018
@benaadams Maybe this is redundant.
But I think it would be nice to have the option to easily create fixed size sub-sequences by just providing an integer.
svick commentedon Sep 22, 2018
Also note that there already was a proposal for this in the past, which was closed: https://github.com/dotnet/corefx/issues/2146.
inputfalken commentedon Sep 22, 2018
@svick Oh i didn't see that one 😐, should I remove the PR then?
svick commentedon Sep 22, 2018
@inputfalken Yes, I think the PR should be closed for now.
[-]IEnumerable should have a extension for creating chunks[/-][+]IEnumerable should have a extension for creating fixed size chunks[/+]karelz commentedon Oct 1, 2018
Is there anything left here or is it just duplicate of #14753?
svick commentedon Oct 1, 2018
@karelz That part of https://github.com/dotnet/corefx/issues/2146 was closed by the question "Is this really common?", with no response given to the people (including me) who think it is common. So maybe its closing could be reconsidered?
(Though that issue is also a mix of unrelated proposals. Keeping this issue open instead might be the better choice.)
karelz commentedon Oct 1, 2018
Alright, I let the new area owners to comment hen they get to it during their incomming triage - @cston @333fred (cc @jaredpar)
eiriktsarpalis commentedon Nov 13, 2020
Chunking is a useful feature which we should consider adding to System.Linq. My preferred signature would be the following:
F# core already has a corresponding
chunkBySizefunction.18 remaining items
inputfalken commentedon Jan 28, 2021
@eiriktsarpalis I would like to grab this if possible. 🙂
Would this be the phase where a pull request is created?
eiriktsarpalis commentedon Jan 28, 2021
@inputfalken absolutely, happy to accept PRs for this work☺️
Add System.Linq Chunk extension method (#47965)