Index: sdk/lib/core/list.dart |
diff --git a/sdk/lib/core/list.dart b/sdk/lib/core/list.dart |
index ecb5535b50e380640a36a5ca9917836c1ca02ecf..98c246caf592848edb6bbaa70fd9e5a01d4141ae 100644 |
--- a/sdk/lib/core/list.dart |
+++ b/sdk/lib/core/list.dart |
@@ -5,22 +5,35 @@ |
part of dart.core; |
/** |
- * A [List] is an indexable collection with a length. It can be of |
- * fixed size or extendable. |
+ * A [List] is an indexable collection with a length. |
+ * |
+ * A `List` implementation can be choose not to support all methods |
+ * of the `List` interface. |
+ * |
+ * The most common list types are: |
+ * * Fixed length list. Does not support operations that changes length. |
+ * * Growable list. Full implmentation of the interface. |
floitsch
2013/02/26 13:54:19
implementation
Lasse Reichstein Nielsen
2013/02/26 15:26:00
Done.
|
+ * * Unmodifiable list. A list where you can't change length or values. |
floitsch
2013/02/26 13:54:19
... list. Changing the length or values yields an
Lasse Reichstein Nielsen
2013/02/26 15:26:00
Example is very long. And reversed doesn't return
|
*/ |
abstract class List<E> implements Collection<E> { |
/** |
* Creates a list of the given [length]. |
* |
- * The length of the returned list is not fixed. |
+ * The list is a fixed-length list if [length] is provided, and an empty |
+ * growable list if [length] is omitted. |
*/ |
- external factory List([int length = 0]); |
+ external factory List([int length]); |
/** |
* Creates a fixed-sized list of the given [length] where each entry is |
floitsch
2013/02/26 13:54:19
fixed-length
Lasse Reichstein Nielsen
2013/02/26 15:26:00
Done.
|
* filled with [fill]. |
*/ |
- external factory List.fixedLength(int length, {E fill: null}); |
+ external factory List.filled(int length, E fill); |
+ |
+ /** |
+ * *Deprecated*: Use `new List(count)` instead. |
+ */ |
+ factory List.fixedLength(int count) => new List(count); |
/** |
* Creates an list with the elements of [other]. The order in |
@@ -28,12 +41,41 @@ abstract class List<E> implements Collection<E> { |
* |
* The length of the returned list is not fixed. |
*/ |
- factory List.from(Iterable other) { |
- var list = new List<E>(); |
+ factory List.from(Iterable other, { bool growable: true }) { |
+ List<E> list = new List<E>(); |
for (E e in other) { |
list.add(e); |
} |
- return list; |
+ if (growable) return list; |
+ int length = list.length; |
+ List<E> fixedList = new List<E>(length); |
+ for (int i = 0; i < length; i++) { |
+ fixedList[i] = list[i]; |
+ } |
+ return fixedList; |
+ } |
+ |
+ /** |
+ * Generate a `List` of elements. |
+ * |
+ * Generates a list of values, where the values are created by |
+ * calling the [generator] function for each index in the range |
+ * 0 .. [length] - 1. |
+ * |
+ * The created length's length is fixed unless [growable] is true. |
+ */ |
+ factory List.generate(int length, E generator(int index), |
+ { bool growable: false }) { |
+ List<E> result; |
+ if (growable) { |
+ result = <E>[]..length = length; |
+ } else { |
+ result = new List<E>(length); |
+ } |
+ for (int i = 0; i < length; i++) { |
+ result[i] = generator(i); |
+ } |
+ return result; |
} |
/** |