Files
lo/docs/data/parallel-times.md
T

760 B

name, slug, sourceRef, category, subCategory, playUrl, similarHelpers, position, signatures, variantHelpers
name slug sourceRef category subCategory playUrl similarHelpers position signatures variantHelpers
Times times parallel/slice.go#L49 parallel slice
core#slice#times
20
func Times[T any](count int, iteratee func(index int) T) []T
parallel#slice#times

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.

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:

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