Skip to content

Commit e0b8a12

Browse files
Merge #713
713: Add conversion into (Option<A>,Option<B>) to EitherOrBoth r=phimuemue a=JustusFluegel Hey! I recently found a conversion into `(Option<A>,Option<B>)` quite useful. Just wondered if there was any interest adding this directly to upstream here. If not, just close this pr :) Thanks Co-authored-by: Justus Fluegel <[email protected]>
2 parents 6ee999c + d7a539f commit e0b8a12

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/either_or_both.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,14 @@ impl<A, B> EitherOrBoth<A, B> {
6565
}
6666
}
6767

68+
/// Return tuple of options corresponding to the left and right value respectively
69+
///
70+
/// If `Left` return `(Some(..), None)`, if `Right` return `(None,Some(..))`, else return
71+
/// `(Some(..),Some(..))`
72+
pub fn left_and_right(self) -> (Option<A>, Option<B>) {
73+
self.map_any(Some, Some).or_default()
74+
}
75+
6876
/// If `Left`, return `Some` with the left value. If `Right` or `Both`, return `None`.
6977
///
7078
/// # Examples
@@ -464,7 +472,7 @@ impl<A, B> EitherOrBoth<A, B> {
464472
impl<T> EitherOrBoth<T, T> {
465473
/// Return either value of left, right, or apply a function `f` to both values if both are present.
466474
/// The input function has to return the same type as both Right and Left carry.
467-
///
475+
///
468476
/// # Examples
469477
/// ```
470478
/// # use itertools::EitherOrBoth;

0 commit comments

Comments
 (0)