This commit is contained in:
a 2022-03-26 17:02:08 -05:00
parent 7a2fb30f61
commit 6c0bbc4632
1 changed files with 16 additions and 0 deletions

View File

@ -25,6 +25,22 @@ func Map[T any](xs []T, fx func(T) T) []T {
wg.Wait()
return lambda.Flatten(spl)
}
func MapV[T, V any](xs []T, fx func(T) T) []V {
spl := lambda.Split(xs, routineCount)
wg := new(sync.WaitGroup)
wg.Add(len(spl))
tmp := make([][]V, len(spl))
for i, v := range spl {
go func(ix int, vx []T) {
spl[ix] = lambda.Map(vx, fx)
wg.Done()
}(i, v)
}
wg.Wait()
return lambda.Flatten(tmp)
}
func Foldl[T any](xs []T, fx func(T, T) T) T {
spl := lambda.Split(xs, routineCount)
wg := new(sync.WaitGroup)