Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(265)

Unified Diff: sdk/lib/core/map.dart

Issue 18023003: Add Map constructors taking iterables. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Removed newline. Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: sdk/lib/core/map.dart
diff --git a/sdk/lib/core/map.dart b/sdk/lib/core/map.dart
index 88776c12721b4d2bbd29211a4879799c4d8539bc..76e66e451a0f3ee8246d11e9d65ec15f528d9b62 100644
--- a/sdk/lib/core/map.dart
+++ b/sdk/lib/core/map.dart
@@ -20,6 +20,35 @@ abstract class Map<K, V> {
factory Map.from(Map<K, V> other) => new HashMap<K, V>.from(other);
/**
+ * Creates a [Map] associating the given [keys] to [values].
+ *
+ * This constructor iterates over [keys] and [values] and maps each element of
+ * [keys] to the corresponding element of [values].
+ *
+ * If [keys] contains the same object multiple times, the last occurrence
+ * overwrites the previous value.
+ *
+ * It is an error if the two [Iterable]s don't have the same length.
+ */
+ factory Map.fromIterables(Iterable<K> keys, Iterable<V> values)
+ = HashMap<K, V>.fromIterables;
+
+ /**
+ * Creates a [Map] where the keys and values are computed from the [iterable].
+ *
+ * For each element of the [iterable] this constructor computes a key/value pair,
floitsch 2013/06/27 13:07:17 long lines.
zarah 2013/06/27 13:13:13 Done.
+ * by applying [key] and [value] respectively.
+ *
+ * The keys of the key/value pairs do not need to be unique. The last occurrence of
floitsch 2013/06/27 13:07:17 long line.
zarah 2013/06/27 13:13:13 Done.
+ * a key will simply overwrite any previous value.
+ *
+ * If no values are specified for [key] and [value] the default is the
+ * identity function.
+ */
+ factory Map.fromIterable(Iterable iterable,
+ {K key(element), V value(element)}) = HashMap<K, V>.fromIterable;
+
+ /**
* Returns whether this map contains the given [value].
*/
bool containsValue(Object value);

Powered by Google App Engine
This is Rietveld 408576698