Update 'parallel/map.go'
This commit is contained in:
parent
2d4b3a96cd
commit
117fe3a563
|
@ -20,14 +20,14 @@ func Map[T any](xs []T, fx func(T) T) []T {
|
||||||
return lambda.Flatten(spl)
|
return lambda.Flatten(spl)
|
||||||
}
|
}
|
||||||
|
|
||||||
func MapV[T, V any](xs []T, fx func(T) T) []V {
|
func MapV[T, V any](xs []T, fx func(T) V) []V {
|
||||||
spl := lambda.Split(xs, routineCount)
|
spl := lambda.Split(xs, routineCount)
|
||||||
wg := new(sync.WaitGroup)
|
wg := new(sync.WaitGroup)
|
||||||
wg.Add(len(spl))
|
wg.Add(len(spl))
|
||||||
tmp := make([][]V, len(spl))
|
tmp := make([][]V, len(spl))
|
||||||
for i, v := range spl {
|
for i, v := range spl {
|
||||||
go func(ix int, vx []T) {
|
go func(ix int, vx []T) {
|
||||||
spl[ix] = lambda.Map(vx, fx)
|
spl[ix] = lambda.MapV(vx, fx)
|
||||||
wg.Done()
|
wg.Done()
|
||||||
}(i, v)
|
}(i, v)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue