Files
lo/docs/data/core-flatmap.md
T
2026-03-02 16:06:51 +01:00

845 B

name, slug, sourceRef, category, subCategory, playUrl, variantHelpers, similarHelpers, position, signatures
name slug sourceRef category subCategory playUrl variantHelpers similarHelpers position signatures
FlatMap flatmap slice.go#L74 core slice https://go.dev/play/p/pFCF5WVB225
core#slice#flatmap
core#slice#flatmaperr
core#slice#map
core#slice#maperr
parallel#slice#map
mutable#slice#map
core#slice#filtermap
40
func FlatMap[T any, R any](collection []T, transform func(item T, index int) []R) []R

Manipulates a slice and transforms and flattens it to a slice of another type. The transform function can either return a slice or a nil, and in the nil case no value is added to the final slice.

out := lo.FlatMap([]int64{0, 1, 2}, func(x int64, _ int) []string {
    return []string{strconv.FormatInt(x, 10), strconv.FormatInt(x, 10)}
})
// []string{"0", "0", "1", "1", "2", "2"}