Skip to content

Commit

Permalink
Allow to use EitherOrBoth<T> to mean the same as EitherOrBoth<T, T>
Browse files Browse the repository at this point in the history
  • Loading branch information
glandium committed Oct 3, 2023
1 parent 0897f56 commit 4e9fc6b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/either_or_both.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use either::Either;

/// Value that either holds a single A or B, or both.
#[derive(Clone, PartialEq, Eq, Hash, Debug)]
pub enum EitherOrBoth<A, B> {
pub enum EitherOrBoth<A, B = A> {
/// Both values are present.
Both(A, B),
/// Only the left value of type `A` is present.
Expand Down
14 changes: 7 additions & 7 deletions tests/merge_join.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use itertools::EitherOrBoth;
fn empty() {
let left: Vec<u32> = vec![];
let right: Vec<u32> = vec![];
let expected_result: Vec<EitherOrBoth<u32, u32>> = vec![];
let expected_result: Vec<EitherOrBoth<u32>> = vec![];
let actual_result = merge_join_by(left, right, |l, r| l.cmp(r)).collect::<Vec<_>>();
assert_eq!(expected_result, actual_result);
}
Expand All @@ -14,7 +14,7 @@ fn empty() {
fn left_only() {
let left: Vec<u32> = vec![1, 2, 3];
let right: Vec<u32> = vec![];
let expected_result: Vec<EitherOrBoth<u32, u32>> = vec![
let expected_result: Vec<EitherOrBoth<u32>> = vec![
EitherOrBoth::Left(1),
EitherOrBoth::Left(2),
EitherOrBoth::Left(3),
Expand All @@ -27,7 +27,7 @@ fn left_only() {
fn right_only() {
let left: Vec<u32> = vec![];
let right: Vec<u32> = vec![1, 2, 3];
let expected_result: Vec<EitherOrBoth<u32, u32>> = vec![
let expected_result: Vec<EitherOrBoth<u32>> = vec![
EitherOrBoth::Right(1),
EitherOrBoth::Right(2),
EitherOrBoth::Right(3),
Expand All @@ -40,7 +40,7 @@ fn right_only() {
fn first_left_then_right() {
let left: Vec<u32> = vec![1, 2, 3];
let right: Vec<u32> = vec![4, 5, 6];
let expected_result: Vec<EitherOrBoth<u32, u32>> = vec![
let expected_result: Vec<EitherOrBoth<u32>> = vec![
EitherOrBoth::Left(1),
EitherOrBoth::Left(2),
EitherOrBoth::Left(3),
Expand All @@ -56,7 +56,7 @@ fn first_left_then_right() {
fn first_right_then_left() {
let left: Vec<u32> = vec![4, 5, 6];
let right: Vec<u32> = vec![1, 2, 3];
let expected_result: Vec<EitherOrBoth<u32, u32>> = vec![
let expected_result: Vec<EitherOrBoth<u32>> = vec![
EitherOrBoth::Right(1),
EitherOrBoth::Right(2),
EitherOrBoth::Right(3),
Expand All @@ -72,7 +72,7 @@ fn first_right_then_left() {
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![
let expected_result: Vec<EitherOrBoth<u32>> = vec![
EitherOrBoth::Left(1),
EitherOrBoth::Right(2),
EitherOrBoth::Left(3),
Expand All @@ -88,7 +88,7 @@ fn interspersed_left_and_right() {
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![
let expected_result: Vec<EitherOrBoth<u32>> = vec![
EitherOrBoth::Left(1),
EitherOrBoth::Right(2),
EitherOrBoth::Both(3, 3),
Expand Down

0 comments on commit 4e9fc6b

Please sign in to comment.