Flatten
Overview
Flatten flattens one level of nested slices (lodash flatten).
If you are coming from Node.js, the closest pattern is _.flatten(arr).
Signature
go
func Flatten[T any](in [][]T) []TCompare: Node.js · Standard Go · gox
js
_.flatten(arr)go
// Manual loop or Go 1.21+ slices package
for _, v := range items {
// transform or filter v
}go
import "github.com/sahilkhaire/gox/slice"
slice.Flatten(arr)Example
go
import "github.com/sahilkhaire/gox/slice"
slice.Flatten(arr)Tips
Chain Filter, Map, and Reduce for lodash-style pipelines. Results are new slices — inputs are never mutated.
Standard library alternative
Use a for loop or Go 1.21+ slices package helpers from the standard library.