Skip to content

Instantly share code, notes, and snippets.

@huonw
Created August 6, 2013 23:45
Show Gist options
  • Save huonw/6169920 to your computer and use it in GitHub Desktop.
Save huonw/6169920 to your computer and use it in GitHub Desktop.
enum StrangeCountIterator { priv A(int), priv B(int) }
impl Iterator<int> for StrangeCountIterator {
fn next(&mut self) -> Option<int> {
match *self {
A(mut i) => {
i += 1;
*self = B(i)
return Some(i);
}
B(mut i) => {
if i % 2 == 0 {
i += 2;
*self = A(i);
return Some(i);
}
goto_keyword_here A(i);
}
}
}
}
fn strange_count() -> StrangeCountIterator {
A(0)
}
yield fn strange_count() -> int {
let mut i = 0;
loop {
i += 1;
yield i;
if i % 2 == 0 {
i += 2;
yield i;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment