use crate::foer_sequences::{FoerSequence, foer_sequence_is_reduced};
use crate::num::exhaustive::PrimitiveIntIncreasingRange;
use crate::tuples::exhaustive::{ExhaustivePairs1Input, exhaustive_pairs_from_single};
use crate::vecs::exhaustive::{ExhaustiveVecs, exhaustive_vecs};
#[derive(Clone, Debug)]
pub struct ExhaustiveFoerSequences<I: Clone + Iterator>(
ExhaustivePairs1Input<ExhaustiveVecs<I::Item, PrimitiveIntIncreasingRange<u64>, I>>,
)
where
I::Item: Clone;
impl<I: Clone + Iterator> Iterator for ExhaustiveFoerSequences<I>
where
I::Item: Clone + Eq,
{
type Item = FoerSequence<I::Item>;
fn next(&mut self) -> Option<FoerSequence<I::Item>> {
loop {
let (non_repeating, repeating) = self.0.next()?;
if foer_sequence_is_reduced(&non_repeating, &repeating) {
return Some(FoerSequence {
non_repeating,
repeating,
});
}
}
}
}
pub fn exhaustive_foer_sequences<I: Clone + Iterator>(xs: I) -> ExhaustiveFoerSequences<I>
where
I::Item: Clone + Eq,
{
ExhaustiveFoerSequences(exhaustive_pairs_from_single(exhaustive_vecs(xs)))
}