Lot of people ask me, hey, Manuel, what is an Iterator and what is an Aggregator? And why should I use them? And when?
And that's why I decided to do this quick video to demonstrate you how it works when you should use did. And you will never have to ask that question again. Hey, my name is Manuel, and I'm the founder of Techflow.
ai, and I work with Integral almost daily. In this video, I will show you exactly what Iterators are, how they are used and when you should use them. And also, I'll show you a little bit more about Aggregators.
So I've paired this little sample scenario here for you where we just request five day forecast from a weather API. It's from an open weather map. So we request a five day weather forecast.
Let me show it to you. So that is the data that we receive. We get a list of all these time entries with individual weather forecasts.
Now, when I connect that to a Row module, and now I just demonstrate it once to you. So we have this here and it sets it up. It has the temperature, the humidity and the wind speed here.
And it puts the date and the time. But that is like it's just one of the entries that we received from the five day forecast, and it's not every entry, but we want to have all of them, of course. And why that is it's because an Array you can see in the data that it shows Array and an Array is basically a list of collections or items.
It can be a simple string. It can be a number or it can be a collection, like in our case, where we have other values inside of that collection and an array can hold one item, it can hold 100 or 1000 items, and it is dynamic. And that is the big point.
If something is dynamic, so the Array, then we want to split it up if we want to process it individually. And since we don't know yet, if there are 40 or 20 or ten or one bundle, we have to use the Iterator to split it up. So basically we split up the array into one, into two, into three, and each of these entries will be processed individually.
So we add the module, the Iterator, and here it expects as an input and Array. So we go in here and select our List Array. So you can see what an Array is with the web brackets.
It shows it's an Array. So it contains a dynamic list. And if we want to access any of these items, if I would just click on any of these, it would add this one here, and that one means it will pick the first entry of that Array and not like the dynamic amount of Arrays.
And that is what a lot of people have problems with. They just do it like this, and then they can't access the other items of Array, but we want to access all of them. We want to process all of them.
And that's why we have to split it up. So I select list as the entry here and we will check the output now of this quickly. So let me run it once.
And if we check this now we have the Array as the input with all these collections. And as the output, we get Bundles, and a bundle will be processed individually throughout the rest of the scenario. So we have bundle number one, which is equal to one, to this data here.
Then we have bundle number two, which will process second. And bundle number three, and so on. And the way you could visualize this is by clicking on that airplane at the bottom.
So if I click on that, it will show. Okay, it makes it API call. We get the list and then the Iterator splits it up and it will add the row individually per item, like per list item.
All right. And now we have to update one thing and that's inside of the Add Row module. We have to use the actual data from the Iterator and not from the five day forecast, because that has still the one here.
So it would use only the first item of our Array list. So when I go in here now and use the value from the Iterator, so this one shows the same value that you would have inside of the list now and you can map it directly from here. And then we'll use dynamic value.
And that is what we need. So for weather, we use main temperature and the humidity and the wind speed. So speed.
And now it will be all dynamic. So we can run it once now and it will add 40 entries inside of our Google sheet. As you can see here.
So it has all these values and we have a dynamic. We split it up. So that is when you should use an Iterator.
I also made this short visualization. So you have the weather forecast. We had the Iterator, and basically it splits it up and processes the rest individually.
And then we are coming to the next part, which is the Aggregator. We're putting everything back together. This can be like a simple Aggregator, or in our case, I will demonstrate it with a Text Aggregator as the source module.
You want to use the Iterator or, for example, you can use a module that outputs multiple bundles, like a Search Rows Google Sheet module. It will output multiple bundles, and then you can use a Text Aggregator or an Aggregator to wait basically until all bundles are at that stage and then combine them in what way you want and then process the rest of the scenario just with one bundle. So with the advanced settings, you can, for example, use New row.
And then we can add like, for example, let's say the temperature and we put the weather type, so rain. And also the weather description is light rain. For example, when we process this now we will add another 40 rows, and then we check the output of the Text Aggregator.
So yeah, here it puts in each individual item again. And then once the 40 has been hit, we check the text output and that combines everything back together. So the Iterator is always one operation used no matter how many items you have, everything that comes after the Iterator will use as many operations as items have been in that Array.
And if you use an Aggregator, it will put everything back together and also use just one operation. And now you can see, okay, bundle one like 40 bundles that came in here from the Iterator. It used that text, and then it combined it all into very long text string.
So this is our final output, and we could use that to send it to Slack if you want like, the forecast inside of Slack message or something like that. So that is how an Iterator works and how an Aggregator works. Iterator splits it up.
An Array Aggregator combines it back together and then you can use it further. And just another example is WooCommerce, for example, or ecommerce in general. If you have a new order coming in, usually you don't know before the order comes in, how many items people purchased or how many different products they've purchased.
So the line items is usually an array inside of WooCommerce. Let's see here the line items. You can see, there's an Array based on the square brackets.
And if you want to process them individually, each line item, or if you want to know how many of these items have they purchased and want to track that somewhere, for example, in the Google sheet, then we have to split it up using the Iterator, then adding a row to a Google sheet or doing another action. Then we can combine it back together. And finally, we can create an invoice, for example, on QuickBooks.
So now we can also do the plane again just to know how the whole flow would look like it split it up into three or how many bundles there are. And then over here at the Text Aggregator, it waits until each bundle has been processed through this thing and then combines it as a text and sets it in the variable. So yeah, I hope you found this valuable.
If you have any more questions about it. Iterators and Aggregators, let me know in the comments below, and I'd be happy to help. Thanks.