-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Map constructors taking Iterables #11330
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
This comment was originally written by @seaneagan So it looks like there will be no Pair/tuple concept in dart (see issue #7088)? Corresponding examples for that approach would be: new Map<int, String>.fromPairs([1, 2].map((i) => new Pair(x, "$x"))); where Iterable has: Iterable<Pair<K, dynamic>> zip(Iterable other); If so, do you plan on instead adding Iterable-like functional methods directly to Map: Iterable map(f(K k, V v)); |
The operations that work on key and value can usually be written in terms of just the key (and access to the map). For example For ease of use, you can write a function from map and binary function to unary function: Then you can do |
This comment was originally written by odw...@google.com Having Map<K, V>.fromIterable(Iterable iterable, { K key(element), V value(element) }); Iterable<K>.toMap({ K key(element), V value(element) } That way we keep the fluentness of Iterable: Map<K,V> map = Iterable.generate(....) instead of: |
We thought of adding a toMap on Iterables, but don't think it is needed that often. Now, with the Iterable constructors it becomes even less useful. |
Set owner to @szakarias. |
Fixed in r=24531. Added Fixed label. |
Add:
Map<K, V>.fromIterable(Iterable iterable, { K key(element), V value(element) });
key and value default to the identity function. (Still a small discussion going for the name of the optional arguments).
and
Map<K, V>.fromIterables(Iterable<K> keys, Iterable<V> values);
Examples:
new Map<int, String>.fromIterable([1, 2], value: (x) => "$x");
new Map<int, String>.fromIterables([1, 2], ["eins", "zwei"]);
The text was updated successfully, but these errors were encountered: