Last active
June 8, 2016 03:44
-
-
Save voddan/3a9442ea7a002855eb7753b8b622677a 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
interface Circular<T> : Iterable<T> { | |
fun state(): T | |
fun inc() | |
fun isZero(): Boolean // `true` in exactly one state | |
fun hasNext(): Boolean // `false` if the next state `isZero()` | |
override fun iterator() : Iterator<T> { | |
return object : Iterator<T> { | |
var started = false | |
override fun next(): T { | |
if(started) | |
inc() | |
else | |
started = true | |
return state() | |
} | |
override fun hasNext() = this@Circular.hasNext() | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment