| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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.core; | 5 part of dart.core; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * An indexable collection of objects with a length. | 8 * An indexable collection of objects with a length. |
| 9 * | 9 * |
| 10 * Subclasses of this class implement different kinds of lists. | 10 * Subclasses of this class implement different kinds of lists. |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 external factory List.filled(int length, E fill); | 83 external factory List.filled(int length, E fill); |
| 84 | 84 |
| 85 /** | 85 /** |
| 86 * Creates a list and initializes it using the contents of [other]. | 86 * Creates a list and initializes it using the contents of [other]. |
| 87 * | 87 * |
| 88 * The [Iterator] of [other] provides the order of the objects. | 88 * The [Iterator] of [other] provides the order of the objects. |
| 89 * | 89 * |
| 90 * This constructor returns a growable list if [growable] is true; | 90 * This constructor returns a growable list if [growable] is true; |
| 91 * otherwise, it returns a fixed-length list. | 91 * otherwise, it returns a fixed-length list. |
| 92 */ | 92 */ |
| 93 factory List.from(Iterable other, { bool growable: true }) { | 93 external factory List.from(Iterable other, { bool growable: true }); |
| 94 List<E> list = new List<E>(); | |
| 95 for (E e in other) { | |
| 96 list.add(e); | |
| 97 } | |
| 98 if (growable) return list; | |
| 99 return makeListFixedLength(list); | |
| 100 } | |
| 101 | 94 |
| 102 /** | 95 /** |
| 103 * Generates a list of values. | 96 * Generates a list of values. |
| 104 * | 97 * |
| 105 * Creates a list with [length] positions and fills it with values created by | 98 * Creates a list with [length] positions and fills it with values created by |
| 106 * calling [generator] for each index in the range `0` .. `length - 1` | 99 * calling [generator] for each index in the range `0` .. `length - 1` |
| 107 * in increasing order. | 100 * in increasing order. |
| 108 * | 101 * |
| 109 * new List<int>.generate(3, (int index) => index * index); // [0, 1, 4] | 102 * new List<int>.generate(3, (int index) => index * index); // [0, 1, 4] |
| 110 * | 103 * |
| (...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 454 * as values. The `Map.keys` [Iterable] iterates the indices of this list | 447 * as values. The `Map.keys` [Iterable] iterates the indices of this list |
| 455 * in numerical order. | 448 * in numerical order. |
| 456 * | 449 * |
| 457 * List<String> words = ['fee', 'fi', 'fo', 'fum']; | 450 * List<String> words = ['fee', 'fi', 'fo', 'fum']; |
| 458 * Map<int, String> map = words.asMap(); | 451 * Map<int, String> map = words.asMap(); |
| 459 * map[0] + map[1]; // 'feefi'; | 452 * map[0] + map[1]; // 'feefi'; |
| 460 * map.keys.toList(); // [0, 1, 2, 3] | 453 * map.keys.toList(); // [0, 1, 2, 3] |
| 461 */ | 454 */ |
| 462 Map<int, E> asMap(); | 455 Map<int, E> asMap(); |
| 463 } | 456 } |
| OLD | NEW |