Documentation
¶
Overview ¶
Package utils contains various util functions
Index ¶
- func MapGetKeyAsType[T any](key string, m map[string]any) (T, error)
- func MapValues[T comparable, U any](input map[T]U) []U
- func SliceDereference[T any](input []*T) []T
- func SliceFilter[T any](input []T, filter func(T) bool) []T
- func SliceFind[T any](input []T, equal func(T) bool) (*T, bool)
- func SliceFlatten[T any](slice [][]T) []T
- func SliceMap[T any, U any](input []T, mapFunc func(T) U) []U
- func SliceMerge[T any](slices ...[]T) []T
- func SliceReference[T any](input []T) []*T
- func SliceRepeat[T any](value T, count int) []T
- func SliceSanitize[T comparable](slice []T) []T
- func SliceToMap[T any, U comparable](input []T, toKey func(T) U) map[U]T
- func SliceUnique[T comparable](input []T) []T
- func SliceUniqueFunc[T any, U comparable](input []T, unique func(t T) U) []T
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MapGetKeyAsType ¶
MapGetKeyAsType retrieves a key from a map and converts it to a given type
func MapValues ¶
func MapValues[T comparable, U any](input map[T]U) []U
MapValues returns a slice of all values
func SliceDereference ¶
func SliceDereference[T any](input []*T) []T
SliceDereference converts a []*T slice to []T
func SliceFilter ¶
SliceFilter returns a new slice consisting of elements that passed the filter function
func SliceFind ¶
SliceFind returns a pointer to the first item determined by the equal function, nil if not found The second argument returns true if found, false otherwise
func SliceMerge ¶
func SliceMerge[T any](slices ...[]T) []T
SliceMerge merges multiple slices together
func SliceReference ¶
func SliceReference[T any](input []T) []*T
SliceReference converts a []T slice to []*T
func SliceRepeat ¶
SliceRepeat constructs a slice of length `count` of element `value`
func SliceSanitize ¶
func SliceSanitize[T comparable](slice []T) []T
SliceSanitize removes all null values according to T{}
func SliceToMap ¶
func SliceToMap[T any, U comparable](input []T, toKey func(T) U) map[U]T
SliceToMap maps a slice to a map with key -> result of toKey function value -> slice entry
func SliceUnique ¶
func SliceUnique[T comparable](input []T) []T
SliceUnique filters out all duplicate elements
func SliceUniqueFunc ¶
func SliceUniqueFunc[T any, U comparable](input []T, unique func(t T) U) []T
SliceUniqueFunc filters out all duplicate elements The unique function should return an comparable that is unique for unique elements
Types ¶
This section is empty.