Skip to main content



      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 07:55 Go to next message
Eclipse UserFriend
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 07:56] by 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 08:10 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

what about list.filter[filterFunction.apply(it)]
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 08:14 Go to previous message
Eclipse UserFriend
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 08:14] by Moderator

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


Current Time: Mon Jul 07 22:39:05 EDT 2025

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

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

Back to the top