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

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

    [ https://issues.apache.org/jira/browse/GROOVY-9845?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17242319#comment-17242319 ] 

Mikko Värri commented on GROOVY-9845:
-------------------------------------

Do you have a better example, because I can get the same result with:

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



> 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
>            Priority: Major
>
> 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)