Merge branch 'rc' of github.com:duke-git/lancet into rc

This commit is contained in:
dudaodong
2025-07-07 10:18:37 +08:00

View File

@@ -125,6 +125,8 @@ func ReduceConcurrent[T any](slice []T, initial T, reducer func(index int, item
func FilterConcurrent[T any](slice []T, predicate func(index int, item T) bool, numThreads int) []T {
result := make([]T, 0)
var wg sync.WaitGroup
var mu sync.Mutex
workerChan := make(chan struct{}, numThreads)
@@ -137,7 +139,9 @@ func FilterConcurrent[T any](slice []T, predicate func(index int, item T) bool,
defer wg.Done()
if predicate(i, v) {
mu.Lock()
result = append(result, v)
mu.Unlock()
}
<-workerChan