-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmap.go
More file actions
26 lines (23 loc) · 730 Bytes
/
map.go
File metadata and controls
26 lines (23 loc) · 730 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
package utils
import "strings"
// LowerMapStringKey :nodoc:
func LowerMapStringKey(v map[string]interface{}) map[string]interface{} {
lv := make(map[string]interface{}, len(v))
for mk, mv := range v {
lv[strings.ToLower(mk)] = mv
}
return lv
}
// MapValuesToOrderedSlice convert map values to ordered slice.
// If the map didn't contain one or more key in the keysOrder slice, then it will be filled with zero value.
func MapValuesToOrderedSlice[K comparable, V any](src map[K]V, keysOrder []K) (orderedMapValues []V) {
var zero V
for _, o := range keysOrder {
if v, ok := src[o]; ok {
orderedMapValues = append(orderedMapValues, v)
continue
}
orderedMapValues = append(orderedMapValues, zero)
}
return
}