-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Add Iterable.groupBy #30376
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
Comments
I'd type it as |
We then also need a |
+1 for this, seems Flutter went ahead and added it: https://docs.flutter.io/flutter/package-collection_collection/groupBy.html |
@rkj: This is just normal @leafpetersen @lrhn feel free to re-open if you still plan to do this. |
This would still be useful as using a top level groupBy breaks the fluent method calls. groupBy(list.map(..).where(..), (item) => ..) |
@vukisoft note that you can now use static extension methods if you want to achieve fluent method calls. |
Iterable.groupBy would be great!
(I'm opening a new issue, instead of re-opening #11159, because the discussion over there was largely about how it would be hard to do without Dart 2.0. I'm opening this issue in the context of Dart 2.0. If this is not the right workflow, we can re-open #11159, and close this.)
Some examples:
(That last one assumes we get an iterator over key/value pairs in Map (#7088) that yields Entry objects. But if its a List or a Pair or a Tuple, whatever.)
I think this is a useful method to have, and also it is expected from developers in other languages. Python2 has groupby; Ruby has Enumerable#group_by, Rust's itertools has GroupBy; It is not to be found in Go, JavaScript (so people use Underscore.js).
Java 8's Collectors has groupingBy which I think is very well thought out; it has a few overloaded variations (could implement similar things in Dart with named arguments), like including a "reduction operation", something like:
Probably unnecessary in Dart, as we have other first class functional means, especially if Map gets a map function (#9590):
The text was updated successfully, but these errors were encountered: