Skip to content

Commit

Permalink
Merge #713
Browse files Browse the repository at this point in the history
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 <justusfluegel@gmail.com>
  • Loading branch information
bors[bot] and JustusFluegel authored Jul 29, 2023
2 parents 6ee999c + d7a539f commit e0b8a12
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/either_or_both.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@ impl<A, B> EitherOrBoth<A, B> {
}
}

/// Return tuple of options corresponding to the left and right value respectively
///
/// If `Left` return `(Some(..), None)`, if `Right` return `(None,Some(..))`, else return
/// `(Some(..),Some(..))`
pub fn left_and_right(self) -> (Option<A>, Option<B>) {
self.map_any(Some, Some).or_default()
}

/// If `Left`, return `Some` with the left value. If `Right` or `Both`, return `None`.
///
/// # Examples
Expand Down Expand Up @@ -464,7 +472,7 @@ impl<A, B> EitherOrBoth<A, B> {
impl<T> EitherOrBoth<T, T> {
/// 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;
Expand Down

0 comments on commit e0b8a12

Please sign in to comment.