Skip to content

Commit 1837435

Browse files
nateboschCommit Queue
authored andcommitted
Mention iteration depth for some Iterable methods
Closes #7797 Most of the other suggestions have already been added, add an explicit mention of shorcutting for `contains`, `firstWhere`, and `single`, [email protected] Change-Id: I53c254839f198a368fcb8734c3f7983b9b3ccad4 CoreLibraryReviewExempt: Doc changes only. Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/310767 Reviewed-by: Lasse Nielsen <[email protected]> Commit-Queue: Nate Bosch <[email protected]>
1 parent b9bcfa7 commit 1837435

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

sdk/lib/core/iterable.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,7 @@ abstract mixin class Iterable<E> {
306306
/// This operation will check each element in order for being equal to
307307
/// [element], unless it has a more efficient way to find an element
308308
/// equal to [element].
309+
/// Stops iterating on the first equal element.
309310
///
310311
/// The equality used to determine whether [element] is equal to an element of
311312
/// the iterable defaults to the [Object.==] of the element.
@@ -665,6 +666,7 @@ abstract mixin class Iterable<E> {
665666
/// Checks that this iterable has only one element, and returns that element.
666667
///
667668
/// Throws a [StateError] if `this` is empty or has more than one element.
669+
/// This operation will not iterate past the second element.
668670
E get single {
669671
Iterator<E> it = iterator;
670672
if (!it.moveNext()) throw IterableElementError.noElement();
@@ -689,6 +691,7 @@ abstract mixin class Iterable<E> {
689691
/// If no element satisfies [test], the result of invoking the [orElse]
690692
/// function is returned.
691693
/// If [orElse] is omitted, it defaults to throwing a [StateError].
694+
/// Stops iterating on the first matching element.
692695
E firstWhere(bool test(E element), {E orElse()?}) {
693696
for (E element in this) {
694697
if (test(element)) return element;

0 commit comments

Comments
 (0)