Skip to content

Instantly share code, notes, and snippets.

@emk
Created October 4, 2014 01:00
Show Gist options
  • Save emk/fde8ff8ecfb2b538d032 to your computer and use it in GitHub Desktop.
Save emk/fde8ff8ecfb2b538d032 to your computer and use it in GitHub Desktop.
Hey, at least it's generic!
pub trait StreamingIterator<'a, T> {
/// Return either the next item in the sequence, or `None` if all items
/// have been consumed.
fn next(&'a mut self) -> Option<T>;
/// Hey, it compiles.
fn reduce<S>(&'a mut self, init: S, r: |S,T| -> S) -> S {
let mut sum = init;
//streaming_for!(v in self, {
// sum = r(sum, v);
//});
sum = r(sum, self.next().unwrap());
sum
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment