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"
-