Documentation ¶
Overview ¶
Package collections contains helper functions for interacting with collection structs like Slices and Maps.
Index ¶
- Constants
- func BatchListIntoGroupsOf[S ~[]E, E any](slice S, batchSize int) []S
- func KeyValueStringSlice(m map[string]string) []string
- func KeyValueStringSliceAsMap(kvPairs []string) map[string][]string
- func KeyValueStringSliceWithFormat[K comparable, V any](m map[K]V, format string) []string
- func Keys[K constraints.Ordered, V any](m map[K]V) []K
- func ListContainsElement[S ~[]E, E comparable](list S, element any) bool
- func MakeCopyOfList[S ~[]E, E comparable](list S) S
- func MergeMaps[K comparable, V any](mapsToMerge ...map[K]V) map[K]V
- func RemoveElementFromList[S ~[]E, E comparable](list S, element any) S
Constants ¶
const (
DefaultKeyValueStringSliceFormat = "%s=%s"
)
Variables ¶
This section is empty.
Functions ¶
func BatchListIntoGroupsOf ¶
BatchListIntoGroupsOf will group the provided slice into groups of size n, with the last of being truncated to the remaining count of elements. Returns nil if n is <= 0
func KeyValueStringSlice ¶ added in v0.12.5
KeyValueStringSlice returns a string slice with key=value items, sorted alphabetically
func KeyValueStringSliceAsMap ¶ added in v0.13.3
KeyValueStringSliceAsMap converts a string slice with key=value items into a map of slice values. The slice will contain more than one item if a key is repeated in the string slice list.
func KeyValueStringSliceWithFormat ¶ added in v0.12.5
func KeyValueStringSliceWithFormat[K comparable, V any](m map[K]V, format string) []string
KeyValueStringSliceWithFormat returns a string slice using the specified format, sorted alphabetically. The format should consist of at least two format specifiers.
func Keys ¶
func Keys[K constraints.Ordered, V any](m map[K]V) []K
Keys returns the keys for the given map, sorted
func ListContainsElement ¶
func ListContainsElement[S ~[]E, E comparable](list S, element any) bool
ListContainsElement returns true if the given list contains the given element
func MakeCopyOfList ¶
func MakeCopyOfList[S ~[]E, E comparable](list S) S
MakeCopyOfList will return a new list that is a copy of the given list.
func MergeMaps ¶
func MergeMaps[K comparable, V any](mapsToMerge ...map[K]V) map[K]V
MergeMaps merges all the maps into one
func RemoveElementFromList ¶
func RemoveElementFromList[S ~[]E, E comparable](list S, element any) S
RemoveElementFromList returns a copy of the given list with all instances of the given element removed
Types ¶
This section is empty.