diff --git a/sliceutils/sliceUtils.go b/sliceutils/sliceUtils.go index c9cc0fb..00d6703 100644 --- a/sliceutils/sliceUtils.go +++ b/sliceutils/sliceUtils.go @@ -80,3 +80,11 @@ func Contains[T comparable](a []T, b T) bool { } return false } + +func Compact[T any](a []T, compactor func(acc T, next T) T) T { + var acc T + for _, v := range a { + acc = compactor(acc, v) + } + return acc +}