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

Unified Diff: sdk/lib/collection/hash_set.dart

Issue 838463002: Change List/Set/Map/Queue.from constructrs to accept any iterable. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 11 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/collection/hash_set.dart
diff --git a/sdk/lib/collection/hash_set.dart b/sdk/lib/collection/hash_set.dart
index c430cf8fa4c5315669119844468ee0bb1e752166..9e13f495f526b345c7fbec30ab609b0fd6da2f51 100644
--- a/sdk/lib/collection/hash_set.dart
+++ b/sdk/lib/collection/hash_set.dart
@@ -71,9 +71,9 @@ abstract class HashSet<E> implements Set<E> {
* An example would be using [identical] and [identityHashCode],
* which is equivalent to using the shorthand [LinkedSet.identity]).
*/
- external factory HashSet({ bool equals(E e1, E e2),
- int hashCode(E e),
- bool isValidKey(potentialKey) });
+ external factory HashSet({bool equals(E e1, E e2),
+ int hashCode(E e),
+ bool isValidKey(potentialKey)});
/**
* Creates an unordered identity-based set.
@@ -85,13 +85,23 @@ abstract class HashSet<E> implements Set<E> {
external factory HashSet.identity();
/**
- * Create a hash set containing the elements of [iterable].
+ * Create a hash set containing all of [elements].
floitsch 2015/01/05 14:45:30 all [elements]. ?
Lasse Reichstein Nielsen 2015/01/06 10:14:45 Done.
*
* Creates a hash set as by `new HashSet<E>()` and adds each element of
- * `iterable` to this set in the order they are iterated.
+ * `elements` to this set in the order they are iterated.
+ *
+ * All the [elements] should be assignable to [E].
Søren Gjesse 2015/01/05 15:35:15 [E] -> `E`
Lasse Reichstein Nielsen 2015/01/06 10:14:45 Why? The [E] is in scope, so we might as well link
Søren Gjesse 2015/01/06 12:09:05 Good - I am not exactly clear on the dartdoc scopi
Lasse Reichstein Nielsen 2015/01/07 07:56:45 The spec tries to specify how references in DartDo
+ * The `elements` iterable itself may have any element type, so this
+ * constructor can be used to down-cast a `Set`, for example as:
+ *
+ * Set<SuperType> superSet = ...;
+ * Set<SubType> subSet =
+ * new HashSet<SubType>.from(superSet.where((e) => e is SubType));
*/
- factory HashSet.from(Iterable<E> iterable) {
- return new HashSet<E>()..addAll(iterable);
+ factory HashSet.from(Iterable elements) {
+ HashSet<E> result = new HashSet<E>();
+ for (E e in elements) result.add(e);
+ return result;
}
/**

Powered by Google App Engine
This is Rietveld 408576698