Iterators
When you need to cycle through a list of things
There is only one iterator in SEL for working with sequences of data like arrays and lists:
Loop
The Loop
event takes an array as its sole argument:
=Loop([1, 4, 3])
This will loop through all 3 values — in the provided order and send them downstream. This also means that the length of the list will determine how many times any events downstream of the Loop
are executed. For instance, if the Loop
points to a Request and contains a list of 3 numbers, that web request will be made 3 times (caching aside).
This can be very useful when you pass the loop the output of a Parser event, which is always a list of matches. Or, yes, the output of Matches which is also always a list.
=Parser('$..email')
-> =Loop()
-> =Response("emails[]")
This will loop through all of the emails output from the Parser
event and append them to the Response Data object's list of values stored at emails
.
Timeless
Unlike most Generators,
Loop
is timeless: it does not have a recurring interval in simulation time. Also, whereas generators likeSource
can and will generate values "forever",Loop
will always terminate when it finishes iterating through its provided input.
Updated 7 months ago