You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "rkrisztian (Jira)" <ji...@apache.org> on 2020/12/02 12:20:00 UTC

[jira] [Created] (GROOVY-9845) Safe star dot operator

rkrisztian created GROOVY-9845:
----------------------------------

             Summary: Safe star dot operator
                 Key: GROOVY-9845
                 URL: https://issues.apache.org/jira/browse/GROOVY-9845
             Project: Groovy
          Issue Type: New Feature
          Components: syntax
            Reporter: rkrisztian


Currently I would have to write code like this (in the Groovy Console) to be safe:

{code:groovy}
def json = [
    messages: [
        [message: 'test']
    ],
    errors: null
]


[
    *(json.messages ? json.messages*.message : []),
    *(json.errors ? json.errors*.message : [])
].join('\n')
{code}

I would like to request for an operator like {{\*?.}} so I can write something like this:

{code:groovy}
[
    *(json.messages?*.message ?: []),
    *(json.errors?*.message ?: [])
].join('\n')
{code}

Not sure if it can be simplified further, but that's the idea.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)