use either::Either;
use crate::IntoNonEmptyIterator;
use crate::NonEmptyIterator;
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
pub enum NEEither<L, R> {
Left(L),
Right(R),
}
impl<L, R> NEEither<L, R> {
pub fn into_nonempty_iter(self) -> NEEither<L::IntoNEIter, R::IntoNEIter>
where
L: IntoNonEmptyIterator,
R: IntoNonEmptyIterator<Item = L::Item>,
{
match self {
NEEither::Left(left) => NEEither::Left(left.into_nonempty_iter()),
NEEither::Right(right) => NEEither::Right(right.into_nonempty_iter()),
}
}
}
impl<L, R> NonEmptyIterator for NEEither<L, R>
where
L: NonEmptyIterator + IntoIterator,
R: NonEmptyIterator + IntoIterator<Item = L::Item>,
{
}
impl<L, R> IntoIterator for NEEither<L, R>
where
L: IntoIterator,
R: IntoIterator<Item = L::Item>,
{
type Item = L::Item;
type IntoIter = Either<L::IntoIter, R::IntoIter>;
fn into_iter(self) -> Self::IntoIter {
match self {
NEEither::Left(left) => Either::Left(left.into_iter()),
NEEither::Right(right) => Either::Right(right.into_iter()),
}
}
}