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

Side by Side Diff: sdk/lib/collection/linked_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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 part of dart.collection; 5 part of dart.collection;
6 6
7 /** 7 /**
8 * A [LinkedHashSet] is a hash-table based [Set] implementation. 8 * A [LinkedHashSet] is a hash-table based [Set] implementation.
9 * 9 *
10 * The `LinkedHashSet` also keep track of the order that elements were inserted 10 * The `LinkedHashSet` also keep track of the order that elements were inserted
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 58
59 /** 59 /**
60 * Creates an insertion-ordered identity-based set. 60 * Creates an insertion-ordered identity-based set.
61 * 61 *
62 * Effectively a shorthand for: 62 * Effectively a shorthand for:
63 * 63 *
64 * new LinkedHashSet(equals: identical, hashCode: identityHashCodeOf) 64 * new LinkedHashSet(equals: identical, hashCode: identityHashCodeOf)
65 */ 65 */
66 external factory LinkedHashSet.identity(); 66 external factory LinkedHashSet.identity();
67 67
68 factory LinkedHashSet.from(Iterable<E> iterable) { 68 /**
69 return new LinkedHashSet<E>()..addAll(iterable); 69 * Create a linked hash set containing all of [elements].
70 *
71 * Creates a linked hash set as by `new LinkedHashSet<E>()` and adds each
72 * element of`elements` to this set in the order they are iterated.
73 *
74 * All the [elements] should be assignable to [E].
75 * The `elements` iterable itself may have any element type,
76 * so this constructor can be used to down-cast a `Set`, for example as:
77 *
78 * Set<SuperType> superSet = ...;
79 * Iterable<SuperType> tmp = superSet.where((e) => e is SubType);
80 * Set<SubType> subSet = new LinkedHashSet<SubType>.from(tmp);
81 */
82 factory LinkedHashSet.from(Iterable<E> elements) {
83 LinkedHashSet<E> result = new LinkedHashSet<E>();
84 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
85 result.add(element);
86 }
87 return result;
70 } 88 }
71 89
72 /** 90 /**
73 * Executes a function on each element of the set. 91 * Executes a function on each element of the set.
74 * 92 *
75 * The elements are iterated in insertion order. 93 * The elements are iterated in insertion order.
76 */ 94 */
77 void forEach(void action(E element)); 95 void forEach(void action(E element));
78 96
79 /** 97 /**
80 * Provides an iterator that iterates over the elements in insertion order. 98 * Provides an iterator that iterates over the elements in insertion order.
81 */ 99 */
82 Iterator<E> get iterator; 100 Iterator<E> get iterator;
83 } 101 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698