Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 /** | 5 /** |
| 6 * The [Collection] interface is the public interface of all | 6 * The [Collection] interface is the public interface of all |
| 7 * collections. | 7 * collections. |
| 8 */ | 8 */ |
| 9 interface Collection<E> extends Iterable<E> { | 9 interface Collection<E> extends Iterable<E> { |
| 10 /** | 10 /** |
| 11 * Applies the function [f] to each element of this collection. | 11 * Applies the function [f] to each element of this collection. |
| 12 */ | 12 */ |
| 13 void forEach(void f(E element)); | 13 void forEach(void f(E element)); |
| 14 | 14 |
| 15 /** | 15 /** |
| 16 * Returns a new collection with the elements [: f(e) :] | 16 * Returns a new collection with the elements [: f(e) :] |
| 17 * for each element [e] of this collection. | 17 * for each element [e] of this collection. |
|
Lasse Reichstein Nielsen
2012/08/08 07:19:14
[:e:]. The 'e' is not referring to an existing var
Anders Johnsen
2012/08/08 07:56:14
I'd like if we could resolve this in another CL. T
Lasse Reichstein Nielsen
2012/08/10 11:26:56
Just fix the [:e:] while you are here, and it'll b
Anders Johnsen
2012/11/12 12:02:56
Done.
| |
| 18 * | 18 * |
| 19 * Note on typing: the return type of f() could be an arbitrary | 19 * Note on typing: the return type of f() could be an arbitrary |
| 20 * type and consequently the returned collection's | 20 * type and consequently the returned collection's |
| 21 * typeis Collection. | 21 * typeis Collection. |
| 22 */ | 22 */ |
| 23 Collection map(f(E element)); | 23 Collection map(f(E element)); |
| 24 | 24 |
| 25 /** | 25 /** |
| 26 * Reduce the entire collection to one value value, startign with [init]. To | |
|
Lasse Reichstein Nielsen
2012/08/08 07:19:14
"starting". This comment is not very descriptive -
Anders Johnsen
2012/08/08 07:56:14
Agreed, this is a way better comment. Updated.
Cr
Lasse Reichstein Nielsen
2012/08/10 11:26:56
"Nice" is such a loaded word :)
Let's drop it for
| |
| 27 * compute e.g. the sum of a Collection of ints, do | |
| 28 * | |
| 29 * collection.reduce(0, (prev, element) => prev + element); | |
| 30 */ | |
| 31 reduce(var init, f(var prev, E element)); | |
|
Lasse Reichstein Nielsen
2012/08/08 07:19:14
Don't abbreviate:
Object reduce(var initialValue
Anders Johnsen
2012/08/08 07:56:14
Returning Object is annoying since you have to 'ca
Lasse Reichstein Nielsen
2012/08/10 11:26:56
Accepted. Use Dynamic or var then.
Anders Johnsen
2012/11/12 12:02:56
Done.
| |
| 32 | |
| 33 /** | |
| 26 * Returns a new collection with the elements of this collection | 34 * Returns a new collection with the elements of this collection |
| 27 * that satisfy the predicate [f]. | 35 * that satisfy the predicate [f]. |
| 28 * | 36 * |
| 29 * An element satisfies the predicate [f] if [:f(element):] | 37 * An element satisfies the predicate [f] if [:f(element):] |
| 30 * returns true. | 38 * returns true. |
| 31 */ | 39 */ |
| 32 Collection<E> filter(bool f(E element)); | 40 Collection<E> filter(bool f(E element)); |
| 33 | 41 |
| 34 /** | 42 /** |
| 35 * Returns true if every elements of this collection satisify the | 43 * Returns true if every elements of this collection satisify the |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 46 /** | 54 /** |
| 47 * Returns true if there is no element in this collection. | 55 * Returns true if there is no element in this collection. |
| 48 */ | 56 */ |
| 49 bool isEmpty(); | 57 bool isEmpty(); |
| 50 | 58 |
| 51 /** | 59 /** |
| 52 * Returns the number of elements in this collection. | 60 * Returns the number of elements in this collection. |
| 53 */ | 61 */ |
| 54 int get length(); | 62 int get length(); |
| 55 } | 63 } |
| OLD | NEW |