Documentation
¶
Overview ¶
Package maputil provides generic helpers for map transformations.
Index ¶
- func Filter[K comparable, V any](m map[K]V, fn func(K, V) bool) map[K]V
- func GetOr[K comparable, V any](m map[K]V, key K, fallback V) V
- func Keys[K comparable, V any](m map[K]V) []K
- func MapValues[K comparable, V any, U any](m map[K]V, fn func(V) U) map[K]U
- func Merge[K comparable, V any](maps ...map[K]V) map[K]V
- func Omit[K comparable, V any](m map[K]V, keys ...K) map[K]V
- func Pick[K comparable, V any](m map[K]V, keys ...K) map[K]V
- func Values[K comparable, V any](m map[K]V) []V
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Filter ¶ added in v0.0.12
func Filter[K comparable, V any](m map[K]V, fn func(K, V) bool) map[K]V
Filter returns a new map containing entries that satisfy fn.
func GetOr ¶ added in v0.0.12
func GetOr[K comparable, V any](m map[K]V, key K, fallback V) V
GetOr returns m[key], or fallback when key does not exist.
func MapValues ¶
func MapValues[K comparable, V any, U any](m map[K]V, fn func(V) U) map[K]U
MapValues transforms map values while preserving keys.
func Merge ¶
func Merge[K comparable, V any](maps ...map[K]V) map[K]V
Merge merges maps into a new map. Later maps override earlier maps.
func Omit ¶
func Omit[K comparable, V any](m map[K]V, keys ...K) map[K]V
Omit returns a new map without selected keys.
func Pick ¶
func Pick[K comparable, V any](m map[K]V, keys ...K) map[K]V
Pick returns a new map containing only selected keys.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.