goutilsgit.mstar.dev/mstar/goutils/maputils Index | Files

package maputils

import "git.mstar.dev/mstar/goutils/maputils"

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

Index

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)

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).

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

Source Files

mapUtils.go

Version
v1.15.0 (latest)
Published
Jun 6, 2025
Platform
linux/amd64
Imports
1 packages
Last checked
1 hour ago

Tools for package owners.