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

Implement multiple-assignment (aka destructuring) via getAt(IntRange) or iterator()

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • None
    • 5.0.0-alpha-1
    • bytecode, groovy-jdk
    • None

    Description

      Currently multiple-assignment is implemented using getAt(int). For types that support getAt(IntRange) it may be more efficient to use that operation. For cases where getAt(int) is a terminal operation (aka streams) it may be the only way to go. Or maybe using one iterator() would be better overall.

      Consider the following:

      Set<String> set = ['foo','bar','baz']
      def (foo, bar, baz) = set // inefficient; requires 3 iterators and 6 calls to next
      
      Stream<String> stream = ['foo','bar','baz'].stream()
      def (foo, bar, baz) = stream // not possible because `getAt(int)` is terminal
      

      Attachments

        Issue Links

          Activity

            People

              emilles Eric Milles
              emilles Eric Milles
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: