Back to Lo

It Chunkentries

docs/data/it-chunkentries.md

1.53.0764 B
Original Source

Chunks a map into smaller maps of the specified size. Returns a sequence of maps, each containing up to the specified number of entries.

go
originalMap := map[string]int{
    "a": 1, "b": 2, "c": 3, "d": 4, "e": 5,
}
result := it.ChunkEntries(originalMap, 2)
// iter.Seq[map[string]int] yielding:
// map[string]int{"a": 1, "b": 2}
// map[string]int{"c": 3, "d": 4}
// map[string]int{"e": 5}

smallMap := map[int]string{1: "one", 2: "two"}
result = it.ChunkEntries(smallMap, 5)
// iter.Seq[map[int]string] yielding:
// map[int]string{1: "one", 2: "two"}

largeMap := make(map[int]bool)
for i := 0; i < 10; i++ {
    largeMap[i] = true
}
result = it.ChunkEntries(largeMap, 3)
// iter.Seq[map[int]bool] yielding 4 maps with 3, 3, 3, and 1 entries respectively