Add map compactor

This commit is contained in:
Melody Becker 2024-12-01 10:31:46 +01:00
parent 7722a73ba2
commit 8d8fe03598

View file

@ -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
}