collections

package
v0.16.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 25, 2023 License: MIT Imports: 5 Imported by: 5

Documentation

Overview

Package collections contains helper functions for interacting with collection structs like Slices and Maps.

Index

Constants

View Source
const (
	DefaultKeyValueStringSliceFormat = "%s=%s"
)

Variables

This section is empty.

Functions

func BatchListIntoGroupsOf

func BatchListIntoGroupsOf[S ~[]E, E any](slice S, batchSize int) []S

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

func KeyValueStringSlice(m map[string]string) []string

KeyValueStringSlice returns a string slice with key=value items, sorted alphabetically

func KeyValueStringSliceAsMap added in v0.13.3

func KeyValueStringSliceAsMap(kvPairs []string) map[string][]string

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL