Back to Lo

Parallel Times

docs/data/parallel-times.md

1.53.0471 B
Original Source

Invokes the predicate count times, returning a slice of the results of each invocation. The predicate is called in parallel with the index as argument.

go
import (
    "strconv"
    lop "github.com/samber/lo/parallel"
)

nums := lop.Times(5, func(i int) string {
    return strconv.Itoa(i)
})
// []string{"0", "1", "2", "3", "4"}

Great for generating data concurrently:

go
ids := lop.Times(10, func(i int) string {
    return fmt.Sprintf("item-%d", i)
})