Skip to content

Intrinsic function: States.ArrayPartition #475

@meenahoda

Description

@meenahoda

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions