Skip to content

Commit a282120

Browse files
nateboschCommit Queue
authored andcommitted
Expand docs for Stream.lastWhere and singleWhere
Closes #30071 Add a template in the `firstWhere` doc for the paragraph about `orElse` handling. Expand the discussion around error handling in the `lastWhere` and `singleWhere` docs without relying on reading the `firstWhere` doc first. [email protected] Change-Id: I302381bb5f4f7daa392ee22bbf667db7d7259ef5 CoreLibraryReviewExempt: Doc changes only. Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/310761 Commit-Queue: Nate Bosch <[email protected]> Reviewed-by: Lasse Nielsen <[email protected]>
1 parent 5940bad commit a282120

File tree

1 file changed

+26
-6
lines changed

1 file changed

+26
-6
lines changed

sdk/lib/async/stream.dart

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1661,10 +1661,12 @@ abstract mixin class Stream<T> {
16611661
/// Returns a future that is completed with the first element of this stream
16621662
/// for which [test] returns `true`.
16631663
///
1664+
/// {@template stream_where_or_else}
16641665
/// If no such element is found before this stream is done, and an
16651666
/// [orElse] function is provided, the result of calling [orElse]
16661667
/// becomes the value of the future. If [orElse] throws, the returned
16671668
/// future is completed with that error.
1669+
/// {@endtemplate}
16681670
///
16691671
/// If this stream emits an error before the first matching element,
16701672
/// the returned future is completed with that error, and processing stops.
@@ -1718,13 +1720,18 @@ abstract mixin class Stream<T> {
17181720

17191721
/// Finds the last element in this stream matching [test].
17201722
///
1721-
/// If this stream emits an error, the returned future is completed with that
1722-
/// error, and processing stops.
1723+
/// Returns a future that is completed with the last element of this stream
1724+
/// for which [test] returns `true`.
1725+
///
1726+
/// {@macro stream_where_or_else}
1727+
///
1728+
/// If this stream emits an error at any point, the returned future is
1729+
/// completed with that error, and the subscription is canceled.
17231730
///
1724-
/// Otherwise as [firstWhere], except that the last matching element is found
1731+
/// A non-error result cannot be provided before this stream is done.
1732+
///
1733+
/// Similar too [firstWhere], except that the last matching element is found
17251734
/// instead of the first.
1726-
/// That means that a non-error result cannot be provided before this stream
1727-
/// is done.
17281735
///
17291736
/// Example:
17301737
/// ```dart
@@ -1770,7 +1777,20 @@ abstract mixin class Stream<T> {
17701777

17711778
/// Finds the single element in this stream matching [test].
17721779
///
1773-
/// Like [lastWhere], except that it is an error if more than one
1780+
/// Returns a future that is completed with the single element of this stream
1781+
/// for which [test] returns `true`.
1782+
///
1783+
/// {@macro stream_where_or_else}
1784+
///
1785+
/// Only one element may match. If more than one matching element is found an
1786+
/// error is thrown, regardless of whether [orElse] was passed.
1787+
///
1788+
/// If this stream emits an error at any point, the returned future is
1789+
/// completed with that error, and the subscription is canceled.
1790+
///
1791+
/// A non-error result cannot be provided before this stream is done.
1792+
///
1793+
/// Similar to [lastWhere], except that it is an error if more than one
17741794
/// matching element occurs in this stream.
17751795
///
17761796
/// Example:

0 commit comments

Comments
 (0)