Skip to content
Node: _.chunk(arr, n)github.com/sahilkhaire/gox/slice

Chunk

Overview

Chunk splits into sub-slices of size (lodash chunk).

If you are coming from Node.js, the closest pattern is _.chunk(arr, n).

Signature

go
func Chunk[T any](in []T, size int) [][]T

Compare: Node.js · Standard Go · gox

js
_.chunk(arr, n)
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.Chunk(arr, n)

Example

go
import "github.com/sahilkhaire/gox/slice"

slice.Chunk(arr, n)

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.

Back to slice package overview

MIT Licensed · Built for Node.js developers moving to Go