Index: sdk/lib/collection/linked_hash_set.dart |
diff --git a/sdk/lib/collection/linked_hash_set.dart b/sdk/lib/collection/linked_hash_set.dart |
index c96d94db571720155511ac3a7bbf228603b5da95..af13525c8b5d03a824c4d3e9dc7cfdebef0d2176 100644 |
--- a/sdk/lib/collection/linked_hash_set.dart |
+++ b/sdk/lib/collection/linked_hash_set.dart |
@@ -65,8 +65,26 @@ abstract class LinkedHashSet<E> implements HashSet<E> { |
*/ |
external factory LinkedHashSet.identity(); |
- factory LinkedHashSet.from(Iterable<E> iterable) { |
- return new LinkedHashSet<E>()..addAll(iterable); |
+ /** |
+ * Create a linked hash set containing all of [elements]. |
+ * |
+ * Creates a linked hash set as by `new LinkedHashSet<E>()` and adds each |
+ * element of`elements` to this set in the order they are iterated. |
+ * |
+ * All the [elements] should be assignable to [E]. |
+ * 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 = ...; |
+ * Iterable<SuperType> tmp = superSet.where((e) => e is SubType); |
+ * Set<SubType> subSet = new LinkedHashSet<SubType>.from(tmp); |
+ */ |
+ factory LinkedHashSet.from(Iterable<E> elements) { |
+ LinkedHashSet<E> result = new LinkedHashSet<E>(); |
+ for (final E element in elements) { |
Søren Gjesse
2015/01/05 15:35:15
Any particular reason for using final here?
Lasse Reichstein Nielsen
2015/01/06 10:14:45
No. Copied it from somewhere else that had a final
|
+ result.add(element); |
+ } |
+ return result; |
} |
/** |