-
Notifications
You must be signed in to change notification settings - Fork 319
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
Either crate style methods for EitherOrBoth #327
Conversation
e51fb7c
to
e8ca207
Compare
I think the defintion of |
Would you consider keeping them with names like trait IsDirection {
fn is_left(&self) -> bool;
fn is_both(&self) -> bool;
fn is_right(&self) -> bool;
}
impl<a, b> IsDirection for EitherOrBoth<a, b> {
fn is_left(&self) -> bool {
match *self {
Left(_) => true,
_ => false,
}
}
fn is_right(&self) -> bool {
match *self {
Right(_) => true,
_ => false,
}
}
fn is_both(&self) -> bool {
self.as_ref().both().is_some()
}
} This brings up an issue, the merits of an either_or_both crate. The only method not included in this pull is that would advocate be included is impl<T> EitherOrBoth<T, T> {
pub fn combine<F>(self, f: F) -> T
where
F: FnOnce(T, T) -> T,
{
match self {
Left(a) => a,
Right(b) => b,
Both(a, b) => f(a, b),
}
}
} What are your thoughts on |
@bluss If you get a chance can you take a look at this again? |
Bump |
Sorry for taking so long to get to this!
After some soul searching, I've decided that the benefits of sticking with the Could you revert f5bfc64, squash, and rebase on master? |
Should be ready to go |
bors r+ |
327: Either crate style methods for EitherOrBoth r=jswrenn a=Avi-D-coder I have recently been using `zip_longest`. Without Functors or lens it's a bit of a pain. @bluss's [either crate](https://crates.io/crates/either) has methods to make dealing with either variants nicer, so I added some of them. I attempted to make the naming and implementation as similar as possible, but there are a few differences. A fallible method of converting `EitherOrBoth` into an `either` would be very useful providing exclusive (not including `Both` variant) methods. Converting should probably wait for rust-lang/rust#33417. Co-authored-by: Avi ד <[email protected]>
Build succeeded |
I have recently been using
zip_longest
. Without Functors or lens it's a bit of a pain.@bluss's either crate has methods to make dealing with either variants nicer, so I added some of them. I attempted to make the naming and implementation as similar as possible, but there are a few differences.
A fallible method of converting
EitherOrBoth
into aneither
would be very useful providing exclusive (not includingBoth
variant) methods. Converting should probably wait for rust-lang/rust#33417.