maps

package
v0.6.3 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2025 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CollectGrouped added in v0.6.3

func CollectGrouped[K comparable, V any](seq iter.Seq2[K, V]) map[K][]V

CollectGrouped consumes a key-value sequence and groups values by key. For each yielded pair (k, v) in seq, it appends v to result[k]. The returned map is initialized and contains slices for all observed keys.

func IntersectKeys added in v0.6.3

func IntersectKeys[K comparable, V any, W any](
	left map[K]V,
	right map[K]W,
) (
	onlyLeft map[K]struct{},
	both map[K]struct{},
	onlyRight map[K]struct{},
)

IntersectKeys computes the relationship between the keys of two maps. It returns three sets (as maps with empty-struct values):

  • onlyLeft: keys present in left but not in right
  • both: keys present in both left and right
  • onlyRight: keys present in right but not in left

The values of the input maps are ignored; only the keys matter.

func Set

func Set[K comparable, V any](m map[K]V, key K, value V) map[K]V

Set sets key to value in the provided map. If the provided map is nil, a new map is created and returned containing the single key-value pair. The (possibly new) map is always returned so callers can safely assign the result back to their variable.

Types

This section is empty.

Jump to

Keyboard shortcuts

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