mirror of
https://github.com/rjNemo/underscore
synced 2026-06-06 18:46:47 +00:00
* add flatmap Signed-off-by: Ruidy <ruidy.nemausat@gmail.com> * add to readme Signed-off-by: Ruidy <ruidy.nemausat@gmail.com> Signed-off-by: Ruidy <ruidy.nemausat@gmail.com> Co-authored-by: Ruidy <ruidy.nemausat@gmail.com>
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
|
|
}
|