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

Consider adding Object deconstruction a-la Javascript

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

Details

    • Improvement
    • Status: Open
    • Major
    • Resolution: Unresolved
    • None
    • None
    • None
    • None

    Description

      In JS you can perform following operations on Arrays:

      const [ a, b, c ] = [ 1, 2, 3 ]
      

      which corresponds to mutli-assignment in Groovy.

      However JS does some really nice syntactic sugar with Object deconstruction on top:

      // "forward"
      const object = { question:'about life', answer:42, z:11 }
      const { question, answer } = object
      
      // "backward"
      const newObject = { question, answer }
      

      This way you can save a lot of code-duplication between declaring variables and Map keys.

      The syntax could look like:

      // "forward"
      def object = [ question:'about life', answer:42, z:11 ]
      def ( question, answer ) = object
      
      // "backward"
      def newObject = [ :question, answer: ]

      What do you think?

      Attachments

        Activity

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

          People

            Unassigned Unassigned
            injecteer@gmail.com Konstantin Smirnov

            Dates

              Created:
              Updated:

              Slack

                Issue deployment