Skip to content

Instantly share code, notes, and snippets.

@brson
Created October 24, 2012 00:11
Show Gist options
  • Save brson/3942852 to your computer and use it in GitHub Desktop.
Save brson/3942852 to your computer and use it in GitHub Desktop.
pub trait BaseIter<A> {
pure fn each(&self, blk: fn(v: &A) -> bool);
pure fn size_hint(&self) -> Option<uint>;
}
pub trait ExtendedIter<A> : BaseIter<A> {
pure fn eachi(&self, blk: fn(uint, v: &A) -> bool) {
let mut i = 0;
// Call a method defined by BaseIter
for self.each |a| {
if !blk(i, a) { break; }
i += 1;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment