Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Using forEach correctly
Using forEach correctly [message #1735701] Wed, 22 June 2016 06:22 Go to next message
chris yo is currently offline chris yoFriend
Messages: 146
Registered: February 2013
Senior Member
I used a forEach in my list but it seems that it deletes the elements.

val x = resource.allContents.toIterable.filter(typeof(Directory))
// x.size here is 5.
x.forEach[isPersonal = true] // set the variable isPersonal to true.
// x.size here is now 0.


What am i doing wrong?
Re: Using forEach correctly [message #1735702 is a reply to message #1735701] Wed, 22 June 2016 06:37 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14655
Registered: July 2009
Senior Member
this is a flaw of the toIterable extension.
it creates an iterator that iterates only one.

solution:

make a copy of the iterable e.g.

.toIterable.toList


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Using forEach correctly [message #1735725 is a reply to message #1735702] Wed, 22 June 2016 09:21 Go to previous message
chris yo is currently offline chris yoFriend
Messages: 146
Registered: February 2013
Senior Member
thanks, your solution works.
Previous Topic:Transforming Xtext DSL to XMI
Next Topic:Rules priority xtext
Goto Forum:
  


Current Time: Mon Mar 04 13:10:39 GMT 2024

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

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

Back to the top