Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » M2M (model-to-model transformation) » [ATL] Iterating over collections
[ATL] Iterating over collections [message #730603] Wed, 28 September 2011 17:06 Go to next message
nicgue is currently offline nicgueFriend
Messages: 2
Registered: 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 Go to previous messageGo to next message
Sylvain EVEILLARD is currently offline Sylvain EVEILLARDFriend
Messages: 556
Registered: 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)})
)
icon14.gif  Re: [ATL] Iterating over collections [solved] [message #730636 is a reply to message #730619] Wed, 28 September 2011 18:45 Go to previous messageGo to next message
nicgue is currently offline nicgueFriend
Messages: 2
Registered: 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 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7680
Registered: 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

Ed Willink

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: Thu Dec 12 22:50:49 GMT 2024

Powered by FUDForum. Page generated in 0.03551 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top