Created
August 6, 2013 23:45
-
-
Save huonw/6169920 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
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) | |
} |
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
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