Documentation
¶
Index ¶
- func CountGrouped[T comparable](elements []T) map[T]int
- func GetDuplicates[T comparable](list []T) []T
- func GroupBy[K comparable, V any](elements []V, keySelector func(V) K) map[K][]V
- func Map[T, V any](ts []T, fn func(T) V) []V
- func RetryUntilSuccessOrCancellation[R interface{}](ctx context.Context, retryInterval time.Duration, ...) (*R, error)
- func ToMap[K comparable, V any](elements []V, keySelector func(V) K) map[K]V
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CountGrouped ¶
func CountGrouped[T comparable](elements []T) map[T]int
CountGrouped counts the occurrences of equal elements (groups). You can use this to determine if there are duplicates or if an element exists.
func GetDuplicates ¶
func GetDuplicates[T comparable](list []T) []T
func GroupBy ¶
func GroupBy[K comparable, V any](elements []V, keySelector func(V) K) map[K][]V
GroupBy groups elements of the original list by the key returned by the given keySelector function applied to each element and returns a map where each group key is associated with a list of corresponding elements.
func Map ¶
func Map[T, V any](ts []T, fn func(T) V) []V
Map returns a slice where each element is the result of invoking fn on each corresponding element of the given slice.
Example:
fruits := []string{"apple", "banana", "raspberry"}
loudFruits := Map(fruits, strings.ToUpper)
fmt.Println(loudFruits)
This should print: [APPLE BANANA RASPBERRY]
func RetryUntilSuccessOrCancellation ¶
func RetryUntilSuccessOrCancellation[R interface{}](
ctx context.Context,
retryInterval time.Duration,
function func(context.Context) (*R, error, bool),
) (*R, error)
RetryUntilSuccessOrCancellation executes the given function in the given interval starting immediately until the given function returns that no retry should be done. The given function needs to return
- a generic value or nil,
- an error and
- a boolean which determines if a retry should happen.
This function returns the result and the error of the given function or nil and the `ctx.Err` if the context is cancelled.
func ToMap ¶
func ToMap[K comparable, V any](elements []V, keySelector func(V) K) map[K]V
Types ¶
This section is empty.