Skip to content

Commit

Permalink
Expand docs for Stream.lastWhere and singleWhere
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
natebosch authored and Commit Queue committed Jun 22, 2023
1 parent 5940bad commit a282120
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions sdk/lib/async/stream.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1661,10 +1661,12 @@ abstract mixin class Stream<T> {
/// Returns a future that is completed with the first element of this stream
/// for which [test] returns `true`.
///
/// {@template stream_where_or_else}
/// If no such element is found before this stream is done, and an
/// [orElse] function is provided, the result of calling [orElse]
/// becomes the value of the future. If [orElse] throws, the returned
/// future is completed with that error.
/// {@endtemplate}
///
/// If this stream emits an error before the first matching element,
/// the returned future is completed with that error, and processing stops.
Expand Down Expand Up @@ -1718,13 +1720,18 @@ abstract mixin class Stream<T> {

/// Finds the last element in this stream matching [test].
///
/// If this stream emits an error, the returned future is completed with that
/// error, and processing stops.
/// Returns a future that is completed with the last element of this stream
/// for which [test] returns `true`.
///
/// {@macro stream_where_or_else}
///
/// If this stream emits an error at any point, the returned future is
/// completed with that error, and the subscription is canceled.
///
/// Otherwise as [firstWhere], except that the last matching element is found
/// A non-error result cannot be provided before this stream is done.
///
/// Similar too [firstWhere], except that the last matching element is found
/// instead of the first.
/// That means that a non-error result cannot be provided before this stream
/// is done.
///
/// Example:
/// ```dart
Expand Down Expand Up @@ -1770,7 +1777,20 @@ abstract mixin class Stream<T> {

/// Finds the single element in this stream matching [test].
///
/// Like [lastWhere], except that it is an error if more than one
/// Returns a future that is completed with the single element of this stream
/// for which [test] returns `true`.
///
/// {@macro stream_where_or_else}
///
/// Only one element may match. If more than one matching element is found an
/// error is thrown, regardless of whether [orElse] was passed.
///
/// If this stream emits an error at any point, the returned future is
/// completed with that error, and the subscription is canceled.
///
/// A non-error result cannot be provided before this stream is done.
///
/// Similar to [lastWhere], except that it is an error if more than one
/// matching element occurs in this stream.
///
/// Example:
Expand Down

0 comments on commit a282120

Please sign in to comment.