Skip to content

Instantly share code, notes, and snippets.

@tzemanovic
Created February 19, 2019 20:51
Show Gist options
  • Save tzemanovic/d60fcff8274be5bf51fde423f73c3f18 to your computer and use it in GitHub Desktop.
Save tzemanovic/d60fcff8274be5bf51fde423f73c3f18 to your computer and use it in GitHub Desktop.
doubler.rs
struct Doubler<I: Iterator> {
iter: I,
}
impl<I> Iterator for Doubler<I>
where
I: Iterator,
I::Item: std::ops::Add<Output = I::Item> + Copy,
{
type Item = I::Item;
fn next(&mut self) -> Option<<Self as Iterator>::Item> {
self.iter.next().map(|x| x + x)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment