[ 
https://issues.apache.org/jira/browse/GROOVY-5291?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Paul King updated GROOVY-5291:
------------------------------
    Fix Version/s:     (was: 3.0.0-alpha-1)

> Add "a ?:= 2" support: should be expanded to "a = a ?: 2"
> ---------------------------------------------------------
>
>                 Key: GROOVY-5291
>                 URL: https://issues.apache.org/jira/browse/GROOVY-5291
>             Project: Groovy
>          Issue Type: Improvement
>          Components: syntax
>            Reporter: Rodrigo Rosenfeld Rosas
>            Assignee: Daniel Sun
>
> This would allow the very common useful idiom found in Ruby:
> {noformat}
> variable ||= value
> {noformat}
> Currently we have to write code like this in Groovy:
> {noformat}
> def myMap = [:]
> if (condition) (myMap[someLongNameObject.getKeyId()] = 
> myMap[someLongNameObject.getKeyId()] ?: []) << someNewValue
> {noformat}
> Also, if getKeyId() is costly or shouldn't get called more than once for some 
> reason, we would have to write it like:
> {noformat}
> def myMap = [:]
> if (condition) {
>   def key = someLongNameObject.getKeyId()
>   (myMap[key] = myMap[key] ?: []) << someNewValue
> }
> {noformat}
> When it could be simplified as this:
> {noformat}
> if (condition) (myMap[someLongNameObject.getKeyId()] ?:= []) << someNewValue
> {noformat}



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)

Reply via email to