This is an old revision of the document!
EACH
Parameters
| Order | Name | Type | Desc |
|---|---|---|---|
| 1 | list | any | The list to iterate through |
| 2 | func | function | The function to execute for every item in the list |
Returns
Copies the stack from every call to func is run onto the stack, followed by a single const with the number of items added.
Description
This command runs the func function for every item in the list array.
This command is mainly used if you want to return data that is broken up on a per-item basis rather than as a whole.
When the func function is run, the index element (the item you're iterating into) is set as the 'index' variable, and is placed as the first element of the stack.
Example
To demonstrate the function, let's look at a simple example.
('Alpha', 'Beta', 'Gamma') ASSET RELS will return a single list of relationships that are present on any of the three assets. This might be useful in some scenarios, but we'd like to know which relationships are present in the individual assets.
We could do this by doing the same basic function three times…
'Alpha' ASSET RELS 'Beta' ASSET RELS 'Gamma' ASSET RELS would do the job, as it would return three distinct lists, one for each asset. But we need to know each of the asset names before-hand, and it would be painful for large lists.
('Alpha', 'Beta', 'Gamma') ASSET [ RELS ] EACH will run the function in the square brackets (RELS) for every item in the list returned by ASSET.
The eventual stack looks like this…