feat: Implement ChunkMap Function (#533) #538
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.