Documentation
¶
Index ¶
- Variables
- func ApplyToSlice[T any](array []T, funcs ...func(T) T)
- func Clamp[T cmp.Ordered](lower, upper, value T) T
- func CloneSlice[T any](array []T) []T
- func CollectChannelMessages[T any](ctx context.Context, c chan T) ([]T, error)
- func CopyMap[K comparable, V any](src map[K]V) map[K]V
- func ExtendMap[K comparable, V any](dst map[K]V, srcs ...map[K]V)
- func FilePathExists(filename string) (bool, error)
- func FilterSlice[T any](array *[]T, filter func(T) bool)
- func GetMapKeys[K comparable, V any](src map[K]V) []K
- func GetMapValues[K comparable, V any](src map[K]V) []V
- func MakeSliceUnique[T comparable](array *[]T)
- func MakeSliceUniqueFunc[T any](array *[]T, hasher func(v T) string)
- func MakeSortedSliceUnique[T comparable](array *[]T)
- func MakeSortedSliceUniqueFunc[T any](array *[]T, equal func(a, b T) bool)
- func MapSlice[T any, R any](array []T, fn func(T) R) []R
- func Max[T constraints.Ordered](a, b T) T
- func Min[T constraints.Ordered](a, b T) T
- func ParallelFor[T any](ctx context.Context, values []T, coroutines int, ...) []error
- func ReadJSONFile(filename string, dst any) error
- func ReduceSlice[T any, R any](array []T, initial R, fn func(R, T) R) R
- func SliceContainsAll[T comparable](haystack []T, needles []T) bool
- func SliceContainsAny[T comparable](haystack []T, needles []T) bool
- func SliceContainsNone[T comparable](haystack []T, needles []T) bool
- func StringContainsAll(s string, needles []string) bool
- func StringContainsAny(s string, needles []string) bool
- func StringContainsNone(s string, needles []string) bool
- func StringMatchesAny(s string, needles []string) bool
- func Try(ctx context.Context, maxAttempts int, waitDuration time.Duration, ...) error
- func Try2[T any](ctx context.Context, maxAttempts int, waitDuration time.Duration, ...) (T, error)
- func WriteJSONFile(filename string, indent string, data any, perm ...fs.FileMode) error
- type Counter
- func (c *Counter[T]) AddKey(key T)
- func (c *Counter[T]) Clear()
- func (c *Counter[T]) Increment(key T)
- func (c *Counter[T]) IncrementBy(key T, value uint)
- func (c *Counter[T]) IncrementByIfKeyExists(key T, value uint) bool
- func (c *Counter[T]) IncrementFunc(fn func(key T, cnt uint) (uint, bool)) bool
- func (c *Counter[T]) IncrementIfKeyExists(key T) bool
- func (c *Counter[T]) KeyExists(key T) bool
- func (c *Counter[T]) KeyExistsFunc(fn func(key T) bool) bool
- func (c *Counter[T]) Keys() []T
- func (c *Counter[T]) Set(key T, cnt uint)
- func (c *Counter[T]) SetToZero()
- func (c *Counter[T]) Values() map[T]uint
- type Maybe
- type Result
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func ApplyToSlice ¶
func ApplyToSlice[T any](array []T, funcs ...func(T) T)
ApplyToSlice applies all functions to the slice
func CloneSlice ¶
func CloneSlice[T any](array []T) []T
CloneSlice returns a new slice with the same values.
func CollectChannelMessages ¶ added in v1.10.0
CollectChannelMessages pulls all messages from the channel, until the channel is closed or the context runs out
func CopyMap ¶ added in v1.8.0
func CopyMap[K comparable, V any](src map[K]V) map[K]V
func ExtendMap ¶ added in v1.8.0
func ExtendMap[K comparable, V any](dst map[K]V, srcs ...map[K]V)
func FilePathExists ¶
FilePathExists check if a file (or directory) exists
func FilterSlice ¶
FilterSlice removes all items from the slice that don't match the filter.
func GetMapKeys ¶ added in v1.8.0
func GetMapKeys[K comparable, V any](src map[K]V) []K
func GetMapValues ¶ added in v1.8.0
func GetMapValues[K comparable, V any](src map[K]V) []V
func MakeSliceUnique ¶
func MakeSliceUnique[T comparable](array *[]T)
MakeSliceUnique removes all but the first appearance of each value.
func MakeSliceUniqueFunc ¶
MakeSliceUniqueFunc removes all but the first appearance of each value. Values are hashed using the hasher function.
func MakeSortedSliceUnique ¶
func MakeSortedSliceUnique[T comparable](array *[]T)
MakeSortedSliceUnique removes all but the first appearance of each value for pre-sorted slices.
func MakeSortedSliceUniqueFunc ¶
MakeSortedSliceUnique removes all but the first appearance of each value for pre-sorted slices. Values are compared using the equal function.
func ParallelFor ¶ added in v1.10.1
func ParallelFor[T any](ctx context.Context, values []T, coroutines int, fn func(context.Context, int, T) error) []error
ParallelFor iterates over the slice in parallel using Goroutines.
func ReadJSONFile ¶
ReadJSONFile reads and decodes the file content into the destination
func ReduceSlice ¶
ReduceSlice returns the reduced value.
func SliceContainsAll ¶
func SliceContainsAll[T comparable](haystack []T, needles []T) bool
SliceContainsAll returns true if all needles are present in the haystack.
func SliceContainsAny ¶
func SliceContainsAny[T comparable](haystack []T, needles []T) bool
SliceContainsAny returns true if one needle is present in the haystack.
func SliceContainsNone ¶
func SliceContainsNone[T comparable](haystack []T, needles []T) bool
SliceContainsNone returns true if no needles are present in the haystack.
func StringContainsAll ¶
func StringContainsAny ¶
func StringContainsNone ¶
func StringMatchesAny ¶
func Try ¶ added in v1.10.0
func Try(ctx context.Context, maxAttempts int, waitDuration time.Duration, f func(ctx context.Context, attempt int) error) error
Try reruns the function until it succeeds or runs out of attempts
Types ¶
type Counter ¶ added in v1.6.0
type Counter[T comparable] struct { // contains filtered or unexported fields }
Counter is a thread safe way to count comparable things.
func NewCounter ¶ added in v1.6.0
func NewCounter[T comparable](keys []T) *Counter[T]
NewCounter creates a new Counter.
func (*Counter[T]) AddKey ¶ added in v1.6.0
func (c *Counter[T]) AddKey(key T)
AddKey adds a key if it doesn't exist already.
func (*Counter[T]) Increment ¶ added in v1.6.0
func (c *Counter[T]) Increment(key T)
Increment adds 1 to the count. If the key doesn't exist, it's created.
func (*Counter[T]) IncrementBy ¶ added in v1.6.0
IncrementBy adds the value to the count. If the key doesn't exist, it's created.
func (*Counter[T]) IncrementByIfKeyExists ¶ added in v1.6.0
Increment adds the value to the count if the key exists and return true.
func (*Counter[T]) IncrementFunc ¶ added in v1.7.0
IncrementFunc iterates over all existing keys. If the fn returned uint is greater than zero, the key will be incremented. If the fn returned bool is false, the iteration is stopped. It returns true if any key was incremented
func (*Counter[T]) IncrementIfKeyExists ¶ added in v1.6.0
Increment adds 1 to the count if the key exists and return true.
func (*Counter[T]) KeyExistsFunc ¶ added in v1.7.0
KeyExistsFunc iterates over all existing keys. If the func returns true, the iteration is stopped and true is returned, otherwise the function returns false.
func (*Counter[T]) Keys ¶ added in v1.7.0
func (c *Counter[T]) Keys() []T
Values returns the map of counts