mirror of
https://github.com/aykhans/dodo.git
synced 2025-09-04 02:13:33 +00:00
✨ Add value generators
This commit is contained in:
@@ -10,14 +10,11 @@ func Flatten[T any](nested [][]*T) []*T {
|
||||
return flattened
|
||||
}
|
||||
|
||||
// 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.
|
||||
// RandomValueCycle returns a function that cycles through the provided values in a pseudo-random order.
|
||||
// Each value in the input slice will be returned before any value is repeated.
|
||||
// If the input slice is empty, the returned function will always return the zero value of type T.
|
||||
// If the input slice contains only one element, that element is always returned.
|
||||
// This function is not thread-safe and should not be called concurrently.
|
||||
func RandomValueCycle[T any](values []T, localRand *rand.Rand) func() T {
|
||||
switch valuesLen := len(values); valuesLen {
|
||||
case 0:
|
||||
|
Reference in New Issue
Block a user