Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add note about Result to find_or_last and find_or_first #984

Merged
merged 1 commit into from
Aug 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1999,6 +1999,15 @@ pub trait Itertools: Iterator {
/// assert_eq!(numbers.iter().find_or_last(|&&x| x > 5), Some(&4));
/// assert_eq!(numbers.iter().find_or_last(|&&x| x > 2), Some(&3));
/// assert_eq!(std::iter::empty::<i32>().find_or_last(|&x| x > 5), None);
///
/// // An iterator of Results can return the first Ok or the last Err:
/// let input = vec![Err(()), Ok(11), Err(()), Ok(22)];
/// assert_eq!(input.into_iter().find_or_last(Result::is_ok), Some(Ok(11)));
///
/// let input: Vec<Result<(), i32>> = vec![Err(11), Err(22)];
/// assert_eq!(input.into_iter().find_or_last(Result::is_ok), Some(Err(22)));
///
/// assert_eq!(std::iter::empty::<Result<(), i32>>().find_or_last(Result::is_ok), None);
/// ```
fn find_or_last<P>(mut self, mut predicate: P) -> Option<Self::Item>
where
Expand Down Expand Up @@ -2027,6 +2036,15 @@ pub trait Itertools: Iterator {
/// assert_eq!(numbers.iter().find_or_first(|&&x| x > 5), Some(&1));
/// assert_eq!(numbers.iter().find_or_first(|&&x| x > 2), Some(&3));
/// assert_eq!(std::iter::empty::<i32>().find_or_first(|&x| x > 5), None);
///
/// // An iterator of Results can return the first Ok or the first Err:
/// let input = vec![Err(()), Ok(11), Err(()), Ok(22)];
/// assert_eq!(input.into_iter().find_or_first(Result::is_ok), Some(Ok(11)));
///
/// let input: Vec<Result<(), i32>> = vec![Err(11), Err(22)];
/// assert_eq!(input.into_iter().find_or_first(Result::is_ok), Some(Err(11)));
///
/// assert_eq!(std::iter::empty::<Result<(), i32>>().find_or_first(Result::is_ok), None);
/// ```
fn find_or_first<P>(mut self, mut predicate: P) -> Option<Self::Item>
where
Expand Down
Loading