Skip to content

Commit

Permalink
Merge #693
Browse files Browse the repository at this point in the history
693: Add example and improve docs for EitherOrBoth::reduce r=phimuemue a=2ndDerivative

Also changed "product" to avoid confusion with multiplication.

This was to address the confusion that led to PR #690 which can be closed in my opinion if this change is added instead. 
Hit me up for any feedback!

Co-authored-by: 2ndDerivative <niclas@klugmann.de>
  • Loading branch information
bors[bot] and 2ndDerivative committed Apr 14, 2023
2 parents ca2af87 + 2958946 commit ad2e401
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/either_or_both.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,16 @@ impl<A, B> EitherOrBoth<A, B> {
}

impl<T> EitherOrBoth<T, T> {
/// Return either value of left, right, or the product of `f` applied where `Both` are present.
/// Return either value of left, right, or apply a function `f` to both values if both are present.
/// The input function has to return the same type as both Right and Left carry.
///
/// # Examples
/// ```
/// # use itertools::EitherOrBoth;
/// assert_eq!(EitherOrBoth::Both(3, 7).reduce(u32::max), 7);
/// assert_eq!(EitherOrBoth::Left(3).reduce(u32::max), 3);
/// assert_eq!(EitherOrBoth::Right(7).reduce(u32::max), 7);
/// ```
pub fn reduce<F>(self, f: F) -> T
where
F: FnOnce(T, T) -> T,
Expand Down

0 comments on commit ad2e401

Please sign in to comment.