Skip to content

Instantly share code, notes, and snippets.

@andr-ggn
Created August 16, 2016 11:40
Show Gist options
  • Save andr-ggn/4dedc4bb6d450c376ff279a4b844586d to your computer and use it in GitHub Desktop.
Save andr-ggn/4dedc4bb6d450c376ff279a4b844586d to your computer and use it in GitHub Desktop.
func iterateEnum<T: Hashable>(_: T.Type) -> AnyGenerator<T> {
var i = 0
return AnyGenerator {
let next = withUnsafePointer(&i) { UnsafePointer<T>($0).memory }
return next.hashValue == i++ ? next : nil
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment