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

Specialize TupleCombinations::fold #775

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion src/adaptors/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,7 @@ macro_rules! impl_tuple_combination {

impl<I, A> Iterator for $C<I>
where I: Iterator<Item = A> + Clone,
I::Item: Clone
A: Clone,
{
type Item = (A, $(ignore_ident!($X, A)),*);

Expand Down Expand Up @@ -761,6 +761,26 @@ macro_rules! impl_tuple_combination {
let n = self.iter.count();
checked_binomial(n, K).unwrap() + self.c.count()
}

fn fold<B, F>(self, mut init: B, mut f: F) -> B
where
F: FnMut(B, Self::Item) -> B,
{
let Self { c, item, mut iter } = self;
init = c
.map(|($($X),*,)| {
Philippe-Cholet marked this conversation as resolved.
Show resolved Hide resolved
let z = item.clone().unwrap();
Philippe-Cholet marked this conversation as resolved.
Show resolved Hide resolved
(z, $($X),*)
})
.fold(init, &mut f);
while let Some(z) = iter.next() {
let c: $P<I> = iter.clone().into();
init = c
.map(|($($X),*,)| (z.clone(), $($X),*))
Philippe-Cholet marked this conversation as resolved.
Show resolved Hide resolved
.fold(init, &mut f);
}
init
}
}

impl<I, A> HasCombination<I> for (A, $(ignore_ident!($X, A)),*)
Expand Down