From ed55b186ba9123ed87b8513e64679fdc38dcb744 Mon Sep 17 00:00:00 2001 From: 2ndDerivative Date: Fri, 14 Apr 2023 19:11:29 +0200 Subject: [PATCH 1/2] Add example of EitherOrBoth::reduce Also changed "product" to avoid confusion with multiplication --- src/either_or_both.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/either_or_both.rs b/src/either_or_both.rs index ef3985f75..c63bc460b 100644 --- a/src/either_or_both.rs +++ b/src/either_or_both.rs @@ -230,7 +230,16 @@ impl EitherOrBoth { } impl EitherOrBoth { - /// 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(self, f: F) -> T where F: FnOnce(T, T) -> T, From a08956f6622024bb4a4ac2b4989eb99edad48092 Mon Sep 17 00:00:00 2001 From: 2ndDerivative Date: Fri, 14 Apr 2023 19:11:29 +0200 Subject: [PATCH 2/2] Add example of EitherOrBoth::reduce Also changed "product" to avoid confusion with multiplication --- src/either_or_both.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/either_or_both.rs b/src/either_or_both.rs index ef3985f75..c63bc460b 100644 --- a/src/either_or_both.rs +++ b/src/either_or_both.rs @@ -230,7 +230,16 @@ impl EitherOrBoth { } impl EitherOrBoth { - /// 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(self, f: F) -> T where F: FnOnce(T, T) -> T,