Details
-
New Feature
-
Status: Closed
-
Minor
-
Resolution: Fixed
-
None
-
None
Description
Deriving from discussion in GROOVY-5785, it would be nice if there were a way to call methods inline which return undesired return values. In the other issue, the example was calling removeAll() to find the difference between two sets:
def extra = set1.clone()
extra.removeAll(set2)
println extra.size()
You could use Object#with() here:
println(set1.clone().with
{ removeAll(set2); it }.size())
The inline() method implies "return it" at the end of the closure:
println(set1.clone().inline
{ removeAll(set2) }.size())
It might even make sense to define a new operator rather than a method, similar to the safe navigation operator:
println(set1.clone()&.removeAll(set2).size())
Attachments
Issue Links
- is related to
-
GROOVY-3976 Alternative to "with" called "tap" that has an implicate "return delegate"
- Closed