Created
October 4, 2014 01:00
-
-
Save emk/fde8ff8ecfb2b538d032 to your computer and use it in GitHub Desktop.
Hey, at least it's generic!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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