{"action":"created","issue":{"url":"https://api.github.com/repos/dotnet/corefx/issues/2146","labels_url":"https://api.github.com/repos/dotnet/corefx/issues/2146/labels{/name}","comments_url":"https://api.github.com/repos/dotnet/corefx/issues/2146/comments","events_url":"https://api.github.com/repos/dotnet/corefx/issues/2146/events","html_url":"https://github.com/dotnet/corefx/issues/2146","id":90670211,"number":2146,"title":"Add commonly required Enumerable methods (DistinctBy, ExceptBy, AsChunked, ...)","user":{"login":"GSPP","id":12032350,"avatar_url":"https://avatars.githubusercontent.com/u/12032350?v=3","gravatar_id":"","url":"https://api.github.com/users/GSPP","html_url":"https://github.com/GSPP","followers_url":"https://api.github.com/users/GSPP/followers","following_url":"https://api.github.com/users/GSPP/following{/other_user}","gists_url":"https://api.github.com/users/GSPP/gists{/gist_id}","starred_url":"https://api.github.com/users/GSPP/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GSPP/subscriptions","organizations_url":"https://api.github.com/users/GSPP/orgs","repos_url":"https://api.github.com/users/GSPP/repos","events_url":"https://api.github.com/users/GSPP/events{/privacy}","received_events_url":"https://api.github.com/users/GSPP/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":24,"created_at":"2015-06-24T13:02:37Z","updated_at":"2015-07-13T11:26:56Z","closed_at":null,"body":"We have Distinct, Except, Intersect, Union, etc. Often it is required, though, to base the set operation on some key. OrderBy can do that for example.\r\n\r\nI request that the following methods be added:\r\n\r\n* DistinctBy (pick the first element deterministically for each key)\r\n* ExceptBy (return all items of the first sequence that do not have a matching key in the second)\r\n* IntersectBy (return the first item in a.Concat(b) for each unique key where the key appears in both collections)\r\n* UnionBy (return the first item in a.Concat(b) for each unique key)\r\n* MaxBy/MinBy\r\n\r\nThe set operations need to deal with duplicate keys in a sensible way. I have added to that list my idea for how to do that in sane and well-defined way.\r\n\r\n<hr>\r\n\r\nAnother commonly required helper method is one that splits a sequence into chunks of a fixed size:\r\n\r\n    static IEnumerable<IEnumerable<T>> AsChunked<T>(this IEnumerable<T> sequence, int chunkSize)\r\n\r\nThis is useful for many things, for example:\r\n\r\n* Split a list into pages\r\n* Make AsParallel operate on coarser items by feeding it chunks\r\n* If you want to save a huge stream of items to files you can use this to split the sequence into one chunk per file\r\n* Request rows from the database in chunks of 1000 IDs\r\n\r\nThis requirement comes up on Stack Overflow a lot and there is no built-in way to do it.\r\n\r\nThe chunks should be drawn lazily. In fact the items of each chunk should be lazy as well. This allows for very big chunks such as 1 billion items per chunk.\r\n\r\nMaybe we need two variants:\r\n\r\n1. `IEnumerable<IEnumerable<T>> AsChunkedLazy`\r\n2. `IEnumerable<T[]> AsChunkedEager`\r\n\r\nThe second one would be easier to handle for consumers. The first one requires more disciplined use because each chunk must be enumerated at most once and the chunks must be enumerated in order. This is required for an efficient streaming operation."},"comment":{"url":"https://api.github.com/repos/dotnet/corefx/issues/comments/120895748","html_url":"https://github.com/dotnet/corefx/issues/2146#issuecomment-120895748","issue_url":"https://api.github.com/repos/dotnet/corefx/issues/2146","id":120895748,"user":{"login":"GSPP","id":12032350,"avatar_url":"https://avatars.githubusercontent.com/u/12032350?v=3","gravatar_id":"","url":"https://api.github.com/users/GSPP","html_url":"https://github.com/GSPP","followers_url":"https://api.github.com/users/GSPP/followers","following_url":"https://api.github.com/users/GSPP/following{/other_user}","gists_url":"https://api.github.com/users/GSPP/gists{/gist_id}","starred_url":"https://api.github.com/users/GSPP/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GSPP/subscriptions","organizations_url":"https://api.github.com/users/GSPP/orgs","repos_url":"https://api.github.com/users/GSPP/repos","events_url":"https://api.github.com/users/GSPP/events{/privacy}","received_events_url":"https://api.github.com/users/GSPP/received_events","type":"User","site_admin":false},"created_at":"2015-07-13T11:26:56Z","updated_at":"2015-07-13T11:26:56Z","body":"I am very strongly in favor of having this built-in and available everywhere. On Stack Overflow we have a lot of questions that would make use of these features. We always have to answer with complicated workarounds or repeat the same code 100 times. There is demand for these things. Stack Overflow is a great place to find evidence for framework deficiencies."}}