Add map compactor
This commit is contained in:
parent
7722a73ba2
commit
8d8fe03598
1 changed files with 12 additions and 0 deletions
|
@ -71,3 +71,15 @@ func CompareMap[K, V comparable](a, b map[K]V) bool {
|
|||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func Compact[K comparable, V any](
|
||||
m map[K]V,
|
||||
compactor func(accK K, accV V, nextK K, nextV V) (K, V),
|
||||
) (K, V) {
|
||||
var accK K
|
||||
var accV V
|
||||
for k, v := range m {
|
||||
accK, accV = compactor(accK, accV, k, v)
|
||||
}
|
||||
return accK, accV
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue