Davide Giuseppe Farella
06/30/2020, 1:49 PMinfix fun A.function(b): X
,
then I have operator fun X.invoke(f: () -> Unit)
so I’m trying to call a function b { ... }
But I get B cannot get invoked as a function, I’ve tried to use plus
a function b +{ ... }
But I got something similar.
If it use infix infix operator fun X.invoke(f: () -> Unit)
is fine ( a function b invoke { ... }
), but cannot get rid of that explicit invoke
If I do like (a function b) { ... }
is also fine, but still ugly 🙂
Any solution?
Thanks 🙂Ruckus
06/30/2020, 2:41 PMDavide Giuseppe Farella
06/30/2020, 2:45 PMa func b run { ... }
OK
a func b + { ... }
NO
😕Ruckus
06/30/2020, 2:49 PM3 * 6 + 4
4 + 3 * 6
Clearly the first should be 22 and the second 42, since the +
came first.Ruckus
06/30/2020, 2:50 PMRuckus
06/30/2020, 2:52 PM(4 + 3) * 6
?Shawn
06/30/2020, 2:55 PMDavide Giuseppe Farella
06/30/2020, 3:11 PM+
was just a try that could be nice, it’s not supposed to be a math stuff.
But why a func b plus { ... }
is fine?Davide Giuseppe Farella
06/30/2020, 3:12 PMRuckus
06/30/2020, 3:15 PMinvoke
is an operator just like plus
. Is your later example, you have no invoke
. That last bit is a lambda passed in to plus
.Davide Giuseppe Farella
06/30/2020, 3:19 PMB
and handle like:
A.func(BPlus)
I might get out if it 🙂Ruckus
06/30/2020, 3:19 PMDavide Giuseppe Farella
06/30/2020, 3:45 PM