Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » [xtend] how to pass a function to method to use in filter
[xtend] how to pass a function to method to use in filter [message #1415244] Tue, 02 September 2014 11:55 Go to next message
Marc Schlegel is currently offline Marc SchlegelFriend
Messages: 69
Registered: July 2009
Member
I am having a little problem with the xTend syntax.

I would like to pass a function to a utility-method, which applies this function to the filter of a list.

private def void doStuff(Iterable<MyType> list, (MyType) => Boolean filterFunction)
{
   val result = list.filter[filterFunction] // syntax-error: cannot convert from (MyType) => (MyType) => Boolean to Function1
  .... work on result
}

...
doStuff(intputList)[e | e.isTrue] // compiles nicely


My filterFunction maps MyType to Boolean, so why cant I use it in InterableExtensions.filter?

Thanks

[Updated on: Tue, 02 September 2014 11:56]

Report message to a moderator

Re: [xtend] how to pass a function to method to use in filter [message #1415251 is a reply to message #1415244] Tue, 02 September 2014 12:10 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Hi,

what about list.filter[filterFunction.apply(it)]


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: [xtend] how to pass a function to method to use in filter [message #1415252 is a reply to message #1415251] Tue, 02 September 2014 12:14 Go to previous message
Marc Schlegel is currently offline Marc SchlegelFriend
Messages: 69
Registered: July 2009
Member
Christian Dietrich wrote on Tue, 02 September 2014 12:10
Hi,

what about list.filter[filterFunction.apply(it)]


Yes, that works. Thanks

And as I just figured out, its even easier when using normal bracket Laughing
list.filter(filterFunction)

[Updated on: Tue, 02 September 2014 12:14]

Report message to a moderator

Previous Topic:changed layout of the composite update site
Next Topic:MWE2 URI resolving
Goto Forum:
  


Current Time: Thu Mar 28 22:23:14 GMT 2024

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

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

Back to the top