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

Intrinsic function: States.ArrayPartition #475

Open
meenahoda opened this issue Oct 17, 2023 · 0 comments
Open

Intrinsic function: States.ArrayPartition #475

meenahoda opened this issue Oct 17, 2023 · 0 comments

Comments

@meenahoda
Copy link
Member

meenahoda commented Oct 17, 2023

States.ArrayPartition

Description from https://states-language.net/#appendix-b

Use the States.ArrayPartition intrinsic function to partition a large array. You can also use this intrinsic to slice the data and then send the payload in smaller chunks.

This intrinsic function takes two arguments. The first argument is an array, while the second argument defines the chunk size. The interpreter chunks the input array into multiple arrays of the size specified by chunk size. The length of the last array chunk may be less than the length of the previous array chunks if the number of remaining items in the array is smaller than the chunk size.

Input validation

You must specify an array as the input value for the function's first argument.

You must specify a non-zero, positive integer for the second argument representing the chunk size value.

The input array can't exceed Step Functions' payload size limit of 256 KB.

For example, given the following input array:

json {"inputArray": [1,2,3,4,5,6,7,8,9] }
You could use the States.ArrayPartition function to divide the array into chunks of four values:

json"inputArray.$": "States.ArrayPartition($.inputArray,4)"
Which would return the following array chunks:

json{"inputArray": [ [1,2,3,4], [5,6,7,8], [9]] }
In the previous example, the States.ArrayPartition function outputs three arrays. The first two arrays each contain four values, as defined by the chunk size. A third array contains the remaining value and is smaller than the defined chunk size.

@meenahoda meenahoda changed the title Intrinsic function: Array.GetPartition Intrinsic function: States.ArrayPartition Oct 17, 2023
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

No branches or pull requests

1 participant