Files
lo/docs/data/core-chunk.md
T
Samuel Berthe fedd0b6d2d doc: explain chunkstring inconsistency (#789)
* doc: explain chunkstring inconsistency

* doc: explain chunkstring inconsistency
2026-01-27 18:53:04 +01:00

882 B

name, slug, sourceRef, category, subCategory, playUrl, variantHelpers, similarHelpers, position, signatures
name slug sourceRef category subCategory playUrl variantHelpers similarHelpers position signatures
Chunk chunk slice.go#L209 core slice https://go.dev/play/p/kEMkFbdu85g
core#slice#chunk
core#slice#slice
core#slice#partitionby
core#slice#drop
core#slice#flatten
core#slice#window
core#slice#sliding
core#map#chunkentries
140
func Chunk[T any, Slice ~[]T](collection Slice, size int) []Slice

Splits a slice into chunks of the given size. The final chunk may be smaller.

lo.Chunk([]int{0, 1, 2, 3, 4, 5}, 2)
// [][]int{{0, 1}, {2, 3}, {4, 5}}

lo.Chunk([]int{0, 1, 2, 3, 4, 5, 6}, 2)
// [][]int{{0, 1}, {2, 3}, {4, 5}, {6}}

Note

lo.ChunkString and lo.Chunk functions behave inconsistently for empty input: lo.ChunkString("", n) returns [""] instead of [].

See https://github.com/samber/lo/issues/788