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

Unified Diff: sdk/lib/core/iterable.dart

Issue 2154933002: Add example int doc for Iterable.expand (Closed) Base URL: https://github.com/dart-lang/sdk@master
Patch Set: Address comment Created 4 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/core/iterable.dart
diff --git a/sdk/lib/core/iterable.dart b/sdk/lib/core/iterable.dart
index 3e7c1cbd97a3327e64d05cff823dcfb37358c120..aa9292eafcaefbdd6a46b5234916ed157ec0fa67 100644
--- a/sdk/lib/core/iterable.dart
+++ b/sdk/lib/core/iterable.dart
@@ -181,6 +181,17 @@ abstract class Iterable<E> {
*
* The returned [Iterable] is lazy, and calls [f] for each element
* of this every time it's iterated.
+ *
+ * Example:
+ *
+ * var pairs = [[1, 2], [3, 4]];
+ * var flattened = pairs.expand((pair) => pair).toList();
+ * print(flattened); // => [1, 2, 3, 4];
+ *
+ * var input = [1, 2, 3];
+ * var duplicated = input.expand((i) => [i, i]).toList();
+ * print(duplicated); // => [1, 1, 2, 2, 3, 3]
+ *
*/
Iterable/*<T>*/ expand/*<T>*/(Iterable/*<T>*/ f(E element)) =>
new ExpandIterable<E, dynamic/*=T*/>(this, f);
@@ -208,7 +219,6 @@ abstract class Iterable<E> {
return false;
}
-
/**
* Applies the function [f] to each element of this collection in iteration
* order.
@@ -316,7 +326,6 @@ abstract class Iterable<E> {
return buffer.toString();
}
-
/**
* Checks whether any element of this iterable satisfies [test].
*
@@ -382,7 +391,7 @@ abstract class Iterable<E> {
*/
bool get isNotEmpty => !isEmpty;
- /**
+ /**
* Returns a lazy iterable of the [count] first elements of this iterable.
*
* The returned `Iterable` may contain fewer than `count` elements, if `this`
@@ -480,7 +489,7 @@ abstract class Iterable<E> {
E result;
do {
result = it.current;
- } while(it.moveNext());
+ } while (it.moveNext());
return result;
}
@@ -506,7 +515,7 @@ abstract class Iterable<E> {
* function is returned.
* If [orElse] is omitted, it defaults to throwing a [StateError].
*/
- E firstWhere(bool test(E element), { E orElse() }) {
+ E firstWhere(bool test(E element), {E orElse()}) {
for (E element in this) {
if (test(element)) return element;
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698