Documentation
¶
Overview ¶
Package mapsutil provides utilities for maps.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SortedByKey ¶
SortedByKey returns an iter.Seq2 of the key-value pairs of the map, sorted by ordered keys . If a key is deleted from the map while the sequence is being iterated, it will be skipped. If a key is added to the map while the sequence is being iterated, it will not be included in the sequence.
Example ¶
m := map[string]int{
"c": 3,
"a": 1,
"b": 2,
}
for k, v := range SortedByKey(m) {
fmt.Println(k, v)
}
Output: a 1 b 2 c 3
func SortedByKeyFunc ¶
func SortedByKeyFunc[M ~map[K]V, K comparable, V any](m M, cmpFunc func(K, K) int) iter.Seq2[K, V]
SortedByKeyFunc is like SortedByKey but the keys are sorted using the provided comparison function.
Example ¶
m := map[string]int{
"c": 3,
"a": 1,
"b": 2,
}
for k, v := range SortedByKeyFunc(m, func(a, b string) int {
return -strings.Compare(a, b)
}) {
fmt.Println(k, v)
}
Output: c 3 b 2 a 1
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.