Skip to content

Instantly share code, notes, and snippets.

@voddan
Last active June 8, 2016 03:44
Show Gist options
  • Save voddan/3a9442ea7a002855eb7753b8b622677a to your computer and use it in GitHub Desktop.
Save voddan/3a9442ea7a002855eb7753b8b622677a to your computer and use it in GitHub Desktop.
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