Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Using toIterable.FindFirst in Generator(IterableExtensions)
Using toIterable.FindFirst in Generator [message #997288] Fri, 04 January 2013 19:00 Go to next message
Michael Colburn is currently offline Michael Colburn
Messages: 8
Registered: November 2012
Junior Member
Newbie question using a simplified example.

Assuming the following Xtext grammar rules:

LibraryResource: 'Resource' name=QualifiedName dsl_Resource_Properties+=Property*;
Property: name=QualifiedName '=' dsl_Property_Text=STRING

And, assuming that among a number of resources there is one as follows:

Resource abc
size = "large"
color = "blue"

Within MyDslGenerator, I want to use findFirst() to get value of
the Property whose name = size
from the resource whose name = abc.

For example,

val item = resource.resourceSet.allContents.toIterable.findFirst(????????)

I see that findFirst expects Iterable<T>, Function1<? super T, Boolean>

But, I have no clue as to how to supply this. I have spend hours, in vain, trying to find an example.

Thank you in advance for taking time to provide me an example of how to use the findFirst function in the context of IterableExtensions.

Re: Using toIterable.FindFirst in Generator [message #997612 is a reply to message #997288] Sat, 05 January 2013 03:11 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6125
Registered: July 2009
Senior Member
Hi you can first filter and downcast by adding a

..toIterable.filter(typeof(MyType))

Then you can pass a closure to the find first

..findFirst[MyType x|x.name=="abc"]) or short
FindFirst[name=="abc"]

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de
Re: Using toIterable.FindFirst in Generator [message #997765 is a reply to message #997612] Tue, 08 January 2013 12:42 Go to previous message
Michael Colburn is currently offline Michael Colburn
Messages: 8
Registered: November 2012
Junior Member
I was able to successfully use this. Thank you for taking the time to answer! I know that you are all very busy, and I appreciate the fact that you are willing to help out with what to you must be very elementary. But, for those of us starting out, it can be very frustrating trying to figure out how to do certain things. I realized that part of the problem is a lack of experience in functional programming. By looking into that as a topic, I better understand what Xtend is capable of.
Previous Topic:how to use types defined in other Ecore files in my DSL
Next Topic:Infer questions
Goto Forum:
  


Current Time: Tue Jul 22 03:34:56 EDT 2014

Powered by FUDForum. Page generated in 0.01727 seconds