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

Allow to use EitherOrBoth<T> to mean the same as EitherOrBoth<T, T> #719

Merged
merged 1 commit into from Oct 3, 2023

Conversation

glandium
Copy link
Contributor

No description provided.

@phimuemue
Copy link
Member

Hi there, thanks for the idea.

Honest question: Does this - apart from avoiding a repeated type - enable something that could not be done with EitherOrBoth as it stands now? (E.g. allow usage in some generic contexts?) Did you experience problems with it?

@glandium
Copy link
Contributor Author

glandium commented Aug 8, 2023

No, I was just trying to avoid the repeated type, which can be bothersome when it's long.

Copy link
Member

@jswrenn jswrenn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a few places in our tests that could take advantage of this change:

let expected_result: Vec<EitherOrBoth<u32, u32>> = vec![
EitherOrBoth::Right(1),
EitherOrBoth::Right(2),
EitherOrBoth::Right(3),
EitherOrBoth::Left(4),
EitherOrBoth::Left(5),
EitherOrBoth::Left(6),
];
let actual_result = merge_join_by(left, right, |l, r| l.cmp(r)).collect::<Vec<_>>();
assert_eq!(expected_result, actual_result);
}
#[test]
fn interspersed_left_and_right() {
let left: Vec<u32> = vec![1, 3, 5];
let right: Vec<u32> = vec![2, 4, 6];
let expected_result: Vec<EitherOrBoth<u32, u32>> = vec![
EitherOrBoth::Left(1),
EitherOrBoth::Right(2),
EitherOrBoth::Left(3),
EitherOrBoth::Right(4),
EitherOrBoth::Left(5),
EitherOrBoth::Right(6),
];
let actual_result = merge_join_by(left, right, |l, r| l.cmp(r)).collect::<Vec<_>>();
assert_eq!(expected_result, actual_result);
}
#[test]
fn overlapping_left_and_right() {
let left: Vec<u32> = vec![1, 3, 4, 6];
let right: Vec<u32> = vec![2, 3, 4, 5];
let expected_result: Vec<EitherOrBoth<u32, u32>> = vec![
EitherOrBoth::Left(1),
EitherOrBoth::Right(2),
EitherOrBoth::Both(3, 3),
EitherOrBoth::Both(4, 4),
EitherOrBoth::Right(5),
EitherOrBoth::Left(6),
];

Can you modify them accordingly?

@jswrenn jswrenn added this to the next milestone Oct 3, 2023
@jswrenn jswrenn added this pull request to the merge queue Oct 3, 2023
Merged via the queue into rust-itertools:master with commit e01c929 Oct 3, 2023
8 checks passed
@jswrenn jswrenn mentioned this pull request Nov 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants