小修
This commit is contained in:
parent
fd951b7ab8
commit
f0028e72f4
0
cache/interface.go → cache/cache.go
vendored
0
cache/interface.go → cache/cache.go
vendored
@ -1,6 +1,8 @@
|
||||
package maps
|
||||
|
||||
import "encoding/json"
|
||||
import (
|
||||
"encoding/json"
|
||||
)
|
||||
|
||||
func StrAnyMapToStruct[T any, M any](m M) (r T, err error) {
|
||||
str, err := json.Marshal(m)
|
||||
@ -54,6 +56,17 @@ func IsExists[K comparable, V any](m map[K]V, k K) bool {
|
||||
return ok
|
||||
}
|
||||
|
||||
func Keys[K comparable, V any](m map[K]V) []K {
|
||||
return FilterToSlice(m, func(k K, v V) (K, bool) {
|
||||
return k, true
|
||||
})
|
||||
}
|
||||
func Values[K comparable, V any](m map[K]V) []V {
|
||||
return FilterToSlice(m, func(k K, v V) (V, bool) {
|
||||
return v, true
|
||||
})
|
||||
}
|
||||
|
||||
func Reduce[T, V any, K comparable](m map[K]V, fn func(K, V, T) T, r T) T {
|
||||
for k, v := range m {
|
||||
r = fn(k, v, r)
|
||||
|
Loading…
Reference in New Issue
Block a user