Skip to content

Instantly share code, notes, and snippets.

@joshuajhomann
Created July 11, 2021 21:09
Show Gist options
  • Save joshuajhomann/2584419abd0d185e9e8ab55c73aa3501 to your computer and use it in GitHub Desktop.
Save joshuajhomann/2584419abd0d185e9e8ab55c73aa3501 to your computer and use it in GitHub Desktop.
extension Collection {
func repeatForever() -> UnfoldSequence<Element, Iterator> {
sequence(state: makeIterator()) { iterator in
iterator.next() ?? {
iterator = makeIterator()
return iterator.next()
}()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment