Help us shape the future of Go! Take the 2026 Go Developer Survey

collections

package
v1.300073.2 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2026 License: MIT Imports: 0 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetOrDefault

func GetOrDefault[K comparable, V any](m map[K]V, key K, defaultValue V) V

GetOrDefault retrieves the value for the key in the map if it exists. If it doesn't exist, then returns the default value.

func MapSlice

func MapSlice[K any, V any](base []K, mapper func(K) V) []V

MapSlice converts a slice of type K into a slice of type V using the provided mapper function.

func MergeMaps

func MergeMaps[K comparable, V any](maps ...map[K]V) map[K]V

MergeMaps merges multiple maps into a new one. Duplicate keys will take the last map's value.

func Range added in v1.300048.0

func Range[T any](values []T, fn func(T) bool) bool

Range evaluates a function against each element in the slice.

func WithNewKeys

func WithNewKeys[K comparable, V any](base map[K]V, keyMapper map[K]K) map[K]V

WithNewKeys re-maps every key in a map as dictated by the mapper. If the key does not have an entry in the mapper, it is left untouched.

Types

type Pair

type Pair[K any, V any] struct {
	Key   K
	Value V
}

Pair is a struct with a K key and V value.

func NewPair

func NewPair[K any, V any](key K, value V) *Pair[K, V]

NewPair creates a new Pair with key and value.

type Set

type Set[K comparable] map[K]struct{}

Set is a map with a comparable K key and no meaningful value.

func NewSet

func NewSet[K comparable](keys ...K) Set[K]

NewSet creates a new Set with the keys provided.

func (Set[K]) Add

func (s Set[K]) Add(keys ...K)

Add keys to the Set.

func (Set[K]) Contains

func (s Set[K]) Contains(key K) bool

Contains whether the key is in the Set.

func (Set[K]) ContainsAll added in v1.300048.0

func (s Set[K]) ContainsAll(other Set[K]) bool

ContainsAll whether the other set is a subset.

func (Set[K]) Equal added in v1.300048.0

func (s Set[K]) Equal(other Set[K]) bool

Equal whether the two sets are the same.

func (Set[K]) Remove

func (s Set[K]) Remove(key K)

Remove a key from the Set.

Jump to

Keyboard shortcuts

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