Details
-
Type:
Improvement
-
Status:
Closed
-
Priority:
Minor
-
Resolution: Fixed
-
Affects Version/s: 1.0-beta-9
-
Fix Version/s: 1.6-beta-2
-
Component/s: None
-
Labels:None
-
Number of attachments :
Description
[-2, -6, 5].collect { if (it < 0) -it; else it }
returns "[null, null, null]," because the parser considers the last statement to be an "if" statement. Instead, we can propagate the optional return to the if and else clauses, so that the above will return [2, 6, 5].
James feels it should only be done for New Groovy.
Since jsr-01, we can use the keyword "return" in closures.
Here is a workaround for jsr-01:
[-2, -6, 5].collect { if (it < 0) return -it; else return it }