Documentation ¶
Overview ¶
Package maputil provides utilities and helpers for scenarios not covered by the pkg/maps package.
Index ¶
- func Keys[M ~map[K]V, K comparable, V any](self M) []K
- func MapToStruct[T any](m map[string]any) (T, error)
- func Merge[M ~map[K]V, K comparable, V any](all ...M) M
- func SortKeys[M ~map[K]V, K comparable, V any](self M, pred func(a, b K) bool) []K
- func SortValues[M ~map[K]V, K comparable, V any](self M, pred func(a, b K) bool) []V
- func SortedKeys[M ~map[K]V, K cmp.Ordered, V any](self M) []K
- func SortedValues[M ~map[K]V, K cmp.Ordered, V any](self M) []V
- func StructToMap[T any](t T) (map[string]any, error)
- func Values[M ~map[K]V, K comparable, V any](self M) []V
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Keys ¶ added in v0.0.2
func Keys[M ~map[K]V, K comparable, V any](self M) []K
Keys gets a slice of all the keys in a map, in arbitrary order.
func MapToStruct ¶ added in v0.0.2
MapToStruct converts a map to a struct by converting through json.
func Merge ¶ added in v0.0.2
func Merge[M ~map[K]V, K comparable, V any](all ...M) M
Merge all the maps into a new map.
func SortKeys ¶ added in v0.0.2
func SortKeys[M ~map[K]V, K comparable, V any](self M, pred func(a, b K) bool) []K
SortKeys gets a slice of all the keys in a map, sorted by a predicate func.
func SortValues ¶ added in v0.0.2
func SortValues[M ~map[K]V, K comparable, V any](self M, pred func(a, b K) bool) []V
SortValues gets a slice of all the values in a map, ordered by the keys, sorted by a predicate func.
func SortedKeys ¶
SortedKeys gets a slice of all the keys in a map, sorted.
func SortedValues ¶ added in v0.0.2
SortedValues gets a slice of all the values in a map, ordered by the keys.
func StructToMap ¶ added in v0.0.2
StructToMap converts a struct to a map by converting through json.
func Values ¶ added in v0.0.2
func Values[M ~map[K]V, K comparable, V any](self M) []V
Values gets a slice of all the values in a map, in arbitrary order.
Types ¶
This section is empty.