Skip to content

Instantly share code, notes, and snippets.

@Ben-G
Created February 3, 2016 16:55
Show Gist options
  • Save Ben-G/82e2b708652f3c654e48 to your computer and use it in GitHub Desktop.
Save Ben-G/82e2b708652f3c654e48 to your computer and use it in GitHub Desktop.
"Infinite" loop with ForwardIndexType and `distanceTo`
struct AIndex: ForwardIndexType {
let index: Int
func successor() -> AIndex {
return AIndex(index: self.index + 1)
}
}
func == (lhs: AIndex, rhs: AIndex) -> Bool {
return lhs.index == rhs.index
}
// Sit and wait...
AIndex(index: 999).distanceTo(AIndex(index: 1))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment