Skip to content

Commit

Permalink
Add note about Result to find_or_last and find_or_first
Browse files Browse the repository at this point in the history
See GH-983
  • Loading branch information
axelkar authored and phimuemue committed Aug 26, 2024
1 parent e2a0a6e commit 91f9618
Showing 1 changed file with 18 additions and 0 deletions.
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

0 comments on commit 91f9618

Please sign in to comment.