This PR introduces a new function ChunkMap, which splits a given map into chunks of a specified size. This functionality helps manage larger datasets by allowing developers to process them in smaller, more manageable pieces.
Changes Made:
Added the ChunkMap function to slice.go.
Implemented a simple chunking mechanism that creates an array of maps.
Added tests to validate the functionality, focusing on the number of chunks produced rather than the order or specific values of the elements.
Usage:
This PR addresses the request made in Issue #533, where the user highlighted the need for a lo.chunk method for maps to simplify batch processing of API requests.
This PR introduces a new function ChunkMap, which splits a given map into chunks of a specified size. This functionality helps manage larger datasets by allowing developers to process them in smaller, more manageable pieces.
Changes Made:
Added the ChunkMap function to slice.go. Implemented a simple chunking mechanism that creates an array of maps. Added tests to validate the functionality, focusing on the number of chunks produced rather than the order or specific values of the elements. Usage:
result := ChunkMap(map[string]int{"a": 1, "b": 2, "c": 3, "d": 4, "e": 5}, 2)
This will return an array of maps, each containing up to 2 key-value pairs from the original map.
Run it on Playground
Reference:
This PR addresses the request made in Issue #533, where the user highlighted the need for a lo.chunk method for maps to simplify batch processing of API requests.