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

Add partition function that allows to partitioning of collections in an easy way #881

Closed
sbuettner opened this issue Jul 29, 2024 · 1 comment · Fixed by #950
Closed

Comments

@sbuettner
Copy link
Contributor

sbuettner commented Jul 29, 2024

Is your feature request related to a problem? Please describe.

We are missing a simple way of partitioning a collection (an array) into several sublists by simply providing the number of elements the collection should be partitioned by. There is the sublist function but its hard to use and a simple way would be very handy to create batches when one wants to split workloads for multi instance processing purposes:

list = [1, 2, 3, "4", "5", 6]
[[1,2], [3, "4"], ["5", 6]] = partition(list, 2)

Describe the solution you'd like

A new partition(array, size) function that splits an array into equals sub arrays each with the maximum number of elements defined by the size argument. This function should handle null values and empty lists gracefully.

// function signature
sliding(list: List, size: Number): List 

// examples
sliding([1,2,3,4,5], 2)
// output: [[1,2], [3,4], [5]]

sliding([], 2)
// output: []

sliding([1], 2)
// output: [[1]]

sliding([1,2], 0)
// output: null

sliding([1,2], -1)
// output: null

Related issues

During a customer interview we found out that there is currently not easy way to split workloads to adhere to API rate limits in the context of: camunda/connectors#2695

@saig0
Copy link
Member

saig0 commented Aug 12, 2024

@sbuettner sounds like a valuable new function. 👍

Feel free to contribute it. 🚀

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

Successfully merging a pull request may close this issue.

2 participants