maputils

package
v1.27.1 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2026 License: MIT Imports: 1 Imported by: 1

Documentation

Overview

Package maputils contains various generic functions for applying an operation on an entire map

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Compact

func Compact[K comparable, V any](
	m map[K]V,
	compactor func(accK K, accV V, nextK K, nextV V) (K, V),
) (K, V)

Compact reduces the keys and values of a map down into one value each. The starting value for each is the default value of that type.

func CompareMap

func CompareMap[K, V comparable](a, b map[K]V) bool

CompareMap compares two maps for key-val equality (If both maps have the same key-value pairs). Deprecated: prefer maps.Equal(a, b)

func FilterMap

func FilterMap[K comparable, V any](dic map[K]V, filter func(K, V) bool) map[K]V

FilterMap filters a map using a given function. If the filter function returns true, the key-value pair stays, otherwise it gets removed.

func KeysFromMap

func KeysFromMap[K comparable, V any](m map[K]V) []K

KeysFromMap creates a slice of keys that match the keys in a given map.

func MapNewKeys

func MapNewKeys[Kin comparable, Vin any, Kout comparable, Vout any](
	in map[Kin]Vin,
	apply func(Kin, Vin) (Kout, Vout),
) map[Kout]Vout

MapNewKeys applies a given function to every key-value pair of a map. The returned map's keys and values may be of different types as the input map The first return value of the apply func will be used as new key, the second as the value

func MapSameKeys

func MapSameKeys[K comparable, V any, R any](dic map[K]V, apply func(K, V) R) map[K]R

MapSameKeys applies a given function to every key-value pair of a map. The returned map's value type may be different from the type of the inital map's value But it will keep the same keys as the input map

Types

This section is empty.

Jump to

Keyboard shortcuts

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