Eclipse Community Forums Forum Search:

Home » Archived » M2M (model-to-model transformation) » [ATL] Iterating over collections
[ATL] Iterating over collections Wed, 28 September 2011 17:06
 nicgueMessages: 2Registered: September 2011 Junior Member
Hi,

i got two sequences: a = Sequence {0,2,3,6}, b = Sequence {2,1,2,1}.
Now i want to create the following string: '(0,2)(2,1)(3,2)(6,1)', similar to the zip function in functional programming. I tried lots of approaches, which didn't work. So, how is this possible without the possibility to iterate over multiple sequences with an iteration counter?

Thank you,

nicgue

[Updated on: Wed, 28 September 2011 17:06]

Report message to a moderator

Re: [ATL] Iterating over collections [message #730619 is a reply to message #730603] Wed, 28 September 2011 17:54
 Sylvain EVEILLARDMessages: 556Registered: July 2009 Senior Member
You do have an iteration counter : the size of the result.
```let a : OclAny = Sequence{0,2,3,6} in
let b : OclAny = Sequence{2,1,2,1} in
a->iterate(e; res : OclAny = Sequence{}|
res.append(Sequence{e,b->at(res.size() + 1)})
)```
Re: [ATL] Iterating over collections [solved] [message #730636 is a reply to message #730619] Wed, 28 September 2011 18:45
 nicgueMessages: 2Registered: September 2011 Junior Member
great, thank you!
Re: [ATL] Iterating over collections [message #730651 is a reply to message #730619] Wed, 28 September 2011 19:05
 Ed WillinkMessages: 7655Registered: July 2009 Senior Member
Hi

Or you can create one

let a : Sequence(Integer) = Sequence{0,2,3,6} in
let b : Sequence(Integer) = Sequence{2,1,2,1} in
Sequence{1..a->size()}->collectNested(e : Integer |
Sequence{a->at(e),b->at(e)})

Regards

On 28/09/2011 18:54, Sylvain EVEILLARD wrote:
> You do have an iteration counter : the size of the result.
> let a : OclAny = Sequence{0,2,3,6} in
> let b : OclAny = Sequence{2,1,2,1} in
> a->iterate(e; res : OclAny = Sequence{}|
> res.append(Sequence{e,b->at(res.size() + 1)})
> )
 Previous Topic: [ATL] MWE2 component Next Topic: How to call a called rule.[ATL]
Goto Forum:

Current Time: Mon Apr 22 07:56:00 GMT 2024