mirror of
https://github.com/rjNemo/underscore
synced 2026-06-06 02:26:42 +00:00
11 lines
375 B
Go
11 lines
375 B
Go
package underscore
|
|
|
|
// Flatmap flatten the input slice element into the new slice. FlatMap maps every element with the help of a mapper function, then flattens the input slice element into the new slice.
|
|
func Flatmap[T any](values []T, mapper func(n T) []T) []T {
|
|
res := make([]T, 0)
|
|
for _, v := range values {
|
|
vs := mapper(v)
|
|
res = append(res, vs...)
|
|
}
|
|
return res
|
|
}
|