Skip to content

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

Merged
jswrenn merged 1 commit into
rust-itertools:masterfrom
glandium:either-or-both-1
Oct 3, 2023
Merged

Allow to use EitherOrBoth<T> to mean the same as EitherOrBoth<T, T>#719
jswrenn merged 1 commit into
rust-itertools:masterfrom
glandium:either-or-both-1

Conversation

@glandium

Copy link
Copy Markdown
Contributor

No description provided.

@phimuemue

Copy link
Copy Markdown
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

glandium commented Aug 8, 2023

Copy link
Copy Markdown
Contributor Author

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

@jswrenn jswrenn left a comment

Copy link
Copy Markdown
Member

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
@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.

3 participants