Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-1676

Implement literal Map addition/concatenation like "[a:1, b:2] + [c:3]"

Attach filesAttach ScreenshotVotersWatch issueWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • New Feature
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.0
    • 1.1-beta-1
    • groovy-jdk
    • None

    Description

      Provide a way to get the result of the "addition" of 2 Maps, eg:

      assert [a:1, b:2] + [c:3] == [a:1, b:2, c:3]
      

      In terms of Map semantics, which would take priority for duplicate keys, left or right?

      Considering Java's Map.putAll(), which blindly adds all elements in the given map, perhaps the right side, should take precedence, so:

      assert [a:1, b:1] + [b:2] == [a:1, b:2]
      

      What do others think?

      Original email thread: http://www.nabble.com/Map-addition-concatenation--tf3122652.html

      Attachments

        1. DefaultGroovyMethods.java
          236 kB
          Maurice Nicholson
        2. MapTest.groovy
          2 kB
          Maurice Nicholson

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            guillaume Guillaume Sauthier
            maurice.nicholson Maurice Nicholson
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment