Skip to content

Instantly share code, notes, and snippets.

@ehsansabet
Forked from mustafaturan/chunk.go
Created January 24, 2022 09:09
Show Gist options
  • Save ehsansabet/38519ed18966b964e64000cebbc75420 to your computer and use it in GitHub Desktop.
Save ehsansabet/38519ed18966b964e64000cebbc75420 to your computer and use it in GitHub Desktop.
Go / Chunk Slice
# https://play.golang.org/p/JxqibtHkuO-
func chunkBy(items []string, chunkSize int) (chunks [][]string) {
for chunkSize < len(items) {
items, chunks = items[chunkSize:], append(chunks, items[0:chunkSize:chunkSize])
}
return append(chunks, items)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment