collections

package
v0.13.5 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2022 License: MIT Imports: 3 Imported by: 40

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(slice []string, batchSize int) [][]string

BatchListIntoGroupsOf will group the provided string slice into groups of size n, with the last of being truncated to the remaining count of strings. 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(m map[string]string, format string) []string

KeyValueStringSliceWithFormat returns a string slice using the specified format, sorted alphabetically. The format should consist of at least two '%s' string verbs.

func Keys

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

Return the keys for the given map, sorted alphabetically

func ListContainsElement

func ListContainsElement(list []string, element string) bool

Return true if the given list contains the given element

func MakeCopyOfList

func MakeCopyOfList(list []string) []string

MakeCopyOfList will return a new list that is a copy of the given list.

func MergeMaps

func MergeMaps(maps ...map[string]interface{}) map[string]interface{}

Merge all the maps into one. Sadly, Go has no generics, so this is only defined for string to interface maps.

func RemoveElementFromList

func RemoveElementFromList(list []string, element string) []string

Return 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