Created
November 12, 2024 12:22
-
-
Save JonCanning/8f07ae554aee7ce8c150849e078b4eee to your computer and use it in GitHub Desktop.
golang circular seq
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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