Created
October 24, 2012 00:11
-
-
Save brson/3942852 to your computer and use it in GitHub Desktop.
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 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