📚 Add function docs

This commit is contained in:
2024-09-15 17:37:25 +04:00
parent 2f37f8c2c1
commit 68bef4a663
2 changed files with 9 additions and 0 deletions

View File

@ -19,6 +19,14 @@ func Contains[T comparable](slice []T, item T) bool {
return false
}
// RandomValueCycle returns a function that cycles through the provided slice of values
// in a random order. Each call to the returned function will yield a value from the slice.
// The order of values is determined by the provided random number generator.
//
// The returned function will cycle through the values in a random order until all values
// have been returned at least once. After all values have been returned, the function will
// reset and start cycling through the values in a random order again.
// The returned function isn't thread-safe and should be used in a single-threaded context.
func RandomValueCycle[Value any](values []Value, localRand *rand.Rand) func() Value {
var (
clientsCount int = len(values)