Skip to content

Commit ad2e401

Browse files
Merge #693
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 <[email protected]>
2 parents ca2af87 + 2958946 commit ad2e401

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/either_or_both.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,16 @@ impl<A, B> EitherOrBoth<A, B> {
230230
}
231231

232232
impl<T> EitherOrBoth<T, T> {
233-
/// Return either value of left, right, or the product of `f` applied where `Both` are present.
233+
/// Return either value of left, right, or apply a function `f` to both values if both are present.
234+
/// The input function has to return the same type as both Right and Left carry.
235+
///
236+
/// # Examples
237+
/// ```
238+
/// # use itertools::EitherOrBoth;
239+
/// assert_eq!(EitherOrBoth::Both(3, 7).reduce(u32::max), 7);
240+
/// assert_eq!(EitherOrBoth::Left(3).reduce(u32::max), 3);
241+
/// assert_eq!(EitherOrBoth::Right(7).reduce(u32::max), 7);
242+
/// ```
234243
pub fn reduce<F>(self, f: F) -> T
235244
where
236245
F: FnOnce(T, T) -> T,

0 commit comments

Comments
 (0)