Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add conversion into (Option<A>,Option<B>) to EitherOrBoth #713

Merged
merged 6 commits into from
Jul 29, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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