function call operator? [message #1751227] |
Thu, 05 January 2017 20:23 |
|
Today I scoured the XTend source code looking for an operator that would do something as simple as taking an input argument, binds it to the scope of a lambda expression and returns the output of the lambda. Maybe I searched wrong but I could not find anything like that.
In the end I implemented it as a method:
def <T, R> R call(T input, Function1<T, R> lambda) {
lambda.apply(input)
}
And it can be used like this:
1.call[i|i+1].call[j|j-1].assertEquals(1)
I just thought it could be useful to have an operator for this.
Questions:
1) Can I use custom operators in XTend?
2) Could we add this operation to the ObjectExtensions class?
|
|
|
|
Re: function call operator? [message #1751232 is a reply to message #1751229] |
Thu, 05 January 2017 22:43 |
|
When using an operator I apparently have to enclose the whole expression in parenthesis if I want to apply another operator.
For example this does not work:
def void test() {
1 >>> [return 10] + 1
}
But this does:
def void test() {
(1 >>> [return 10]) + 1
}
When the syntax used is a method call, the next operator can be written right after. I'm not sure I understand the reason why. Could it be related to operator precedence?
|
|
|
Re: function call operator? [message #1751248 is a reply to message #1751232] |
Fri, 06 January 2017 09:20 |
Jan Koehnlein Messages: 760 Registered: July 2009 Location: Hamburg |
Senior Member |
|
|
Yes, operator precedence is fixed.
As we're using Antlr,the precedence is defined by the call hierarchy in the Xtend grammar. You cannot change that on library level.
---
Get professional support from the Xtext committers at www.typefox.io
|
|
|
Powered by
FUDForum. Page generated in 0.04061 seconds