Details
Description
This would allow the very common useful idiom found in Ruby:
variable ||= value
Currently we have to write code like this in Groovy:
def myMap = [:] if (condition) (myMap[someLongNameObject.getKeyId()] = myMap[someLongNameObject.getKeyId()] ?: []) << someNewValue
Also, if getKeyId() is costly or shouldn't get called more than once for some reason, we would have to write it like:
def myMap = [:]
if (condition) {
def key = someLongNameObject.getKeyId()
(myMap[key] = myMap[key] ?: []) << someNewValue
}
When it could be simplified as this:
if (condition) (myMap[someLongNameObject.getKeyId()] ?:= []) << someNewValue
Issue Links
- is related to
-
GROOVY-5306
Add "a ?= 2" support: should be expanded to "a = a == null ? 2 : a"
-
Activity
blackdrag blackdrag
made changes -
| Field | Original Value | New Value |
|---|---|---|
| Status | Open [ 1 ] | Closed [ 6 ] |
| Assignee | blackdrag blackdrag [ blackdrag ] | |
| Resolution | Won't Fix [ 2 ] |
Rodrigo Rosenfeld Rosas
made changes -
| Resolution | Won't Fix [ 2 ] | |
| Status | Closed [ 6 ] | Reopened [ 4 ] |
Guillaume Laforge
made changes -
| Link | This issue is related to GROOVY-5306 [ GROOVY-5306 ] |
blackdrag blackdrag
made changes -
| Assignee | blackdrag blackdrag [ blackdrag ] | |
| Fix Version/s | 4.0 [ 18928 ] |