Skip to content

Instantly share code, notes, and snippets.

@JonCanning
Created November 12, 2024 12:22
Show Gist options
  • Save JonCanning/8f07ae554aee7ce8c150849e078b4eee to your computer and use it in GitHub Desktop.
Save JonCanning/8f07ae554aee7ce8c150849e078b4eee to your computer and use it in GitHub Desktop.
golang circular seq
func circularSeq[T any](values []T) iter.Seq[T] {
i := 0
return func(yield func(T) bool) {
value := values[i]
i++
if i == len(values) {
i = 0
}
if !yield(value) {
return
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment