[
https://issues.apache.org/jira/browse/GROOVY-8071?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17156835#comment-17156835
]
Suminda Dharmasena commented on GROOVY-8071:
--------------------------------------------
[Concurnas|https://concurnas.com/] supports
{code:java}
robot..up()..up()..left()..down()..right()
{code}
which is equivalent to
{code:java}
robot.*[.up(), .up(), .left(), .down(), .right()]
{code}
in my proposal above.
This can be supported in the current scheme of things where "robot" is made the
owner or deligate and .up(), .up(), .left(), .down(), .right() are sent to it.
Combining this with the spread operator:
{code:java}
[robot1, robot2]*.*[.up(), .up(), .left(), .down(), .right()]{code}
.up(), .up(), .left(), .down(), .right() are called on robot1 followed by
robot2.
{code:java}
def a = .f{code}
will create a closure with no delegate or owner.
{code:java}
obj.a(){code}
will set the delegate or owner to obj and evaluate the closure.
For efficiency perhaps actually creating closures and evoking the methods can
be skipped if there is an optimised way to achieve equivalent results.
> 1st Class Messages
> ------------------
>
> Key: GROOVY-8071
> URL: https://issues.apache.org/jira/browse/GROOVY-8071
> Project: Groovy
> Issue Type: Improvement
> Reporter: Suminda Dharmasena
> Priority: Major
>
> Just like the spread operator it would be good to have something similar to
> saving and calling function.
> E.g.
> ```
> def aCall = .equals(obj1)
> obj2.*aCall(obj1) // same as obj2.equals(obj1)
> ```
> Deciding to call and placing the call happens in 2 different instances.
> ```
> def l1 = [ .f1(a), .f2(b)]
> myObj.*l1
> // similarly
> myObj.*[ .f1(a), .f2(b)]
> myObj.*[ .f1 : a, .f2 : b]
> ```
> Calls both f1 and f2 and return the results as a list of 2 items.
> ```
> [obj1, obj2].*f1()
> ```
> Call f1 on both objects. Same as spread, but
> ```
> [obj1, obj2].*[.f1(), .f2()]
> ```
> Calls f1 and f2 on obj1 followed by obj2 returning nested list of the 2
> values.
> ```
> [ Obj1.f1 : a, Obj1.f : b].*[.f3: c, .f4 : d]
> ```
> Call returning [Obj1.f1(a).f3(c), Obj1.f1(a).f4(d), Obj2.f2(b).f3(c),
> Obj2.f2(b).f4(d)]
> If you do not want to complete cross product you can have another operator
> say `.**` to mean you call on the objects on the corresponding index. Or you
> can have this as `.*` and `.**` for the full cross product.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)