Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Implement ChunkMap Function (#533) #538

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

oswaldom-code
Copy link

@oswaldom-code oswaldom-code commented Sep 23, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant