Enhanced For Each

By Ricardo Silva on 19 Apr 2011
I'm sure the following pattern will be familiar to many Agile Platform Users. It is indeed a pretty common pattern:

The purpose here is to generate a new record list based on some records from another record list. We would have a variable holding a temporary record of the same kind as the "destination" list, and also a destination list holding all the new records.

This, my friends, is a List Comprehension. There are a few issues that come up when implementing list comprehensions like this in the Agile Platform, and they have to do with variable scope. We need to add temporary variables to hold both the list and the record currently being built, and these will polute the Action namespace. Also this is a simple, common and powerful enough pattern to warrant having it in our language.

In the Agile Platform a lot of what we do is manipulating lists, and as such I propose we add List Comprehensions to our simple Agile Platform language. This could be done extending the For Each node (or creating a new, similar one) with a couple of extra arguments. One would be a condition (we could have a neat editor for it, like in the Simple Query conditions) over the records being iterated, the other would be an Output Record Definition declaring what was the type of the (you guessed it) output record list.

As all elements in the Agile Platform language need to be simple (which entails that they can be explained in a simple way) I can see how this concept might seem too complicated. But think about the following description of the new Enhanced For Each: "Iterate or Transform a Record List". Doesn't seem so daunting now, does it? (might need a little more work, but I think the idea is simple enough to pass on)

One thing that would be very neat to have on the Agile Platform would be a way to perform Simple Queries on Record Lists, and List Comprehensions would allow that. And much more.
Hermínio Mira29 Apr 2011
This would be great, I've actually been planning on suggesting something like this but you just nailed it!