This is a tutorial for slicing an array into multiple operations.
This is usually needed for external API calls that has a maximum array limit, so we need to split into a smaller batch size (also known as “chunk”, or “chunking”) per operation.
Original Solution
The original solution suggested using three modules with a complex filter:
This uses 2n + 1
operations, n
being the number of chunks needed. For example, if we have 1000 items, and we want to output arrays sizes of 100 per operation (10 operations), we require 2*10 + 1
= 21
operations.
The Slice Function
Did you know that you can use the built-in slice
function to get selected sub-items from an array?
The slice
tooltip states:
Proposed Solution
The new solution only requires 1
operation (a single operation) no matter how many chunks we need:
This is because instead of using an Iterator-Aggregator pair to group the chunks, we can directly use the slice
function in your “Make an API Call” module itself!
For example, if we have 1000 items, and we want to output arrays sizes of 100 per operation (10 operations), we require 1
operation (just the repeater module) to generate the 10 bundles (operations).
samliew – request private consultation
Join the Make Fans Discord server to chat with other makers!