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

ASF GitHub Bot commented on GROOVY-5744:
----------------------------------------

eric-milles opened a new pull request, #1756:
URL: https://github.com/apache/groovy/pull/1756

   Support multi-assign for `Stream` and `Iterator`.  Improve efficiency of 
multi-assign for types like `Set` and `Collection` which do not support direct 
indexing.
   
   Translate "def (one,two) = rhs" into (pseudo-code):
   ```groovy
   def iter = rhs.iterator(), first
   if (iter.hasNext() && (first = iter.next()) !== rhs) {
       def one = first
       def two = iter.hasNext() ? iter.next() : null
   } else {
     def one = rhs.getAt(0)
     def two = rhs.getAt(1)
   }
   ```
   
   https://issues.apache.org/jira/browse/GROOVY-10666
   https://issues.apache.org/jira/browse/GROOVY-5744




> Multiple assignment from Iterator skips every other element
> -----------------------------------------------------------
>
>                 Key: GROOVY-5744
>                 URL: https://issues.apache.org/jira/browse/GROOVY-5744
>             Project: Groovy
>          Issue Type: Bug
>          Components: groovy-runtime
>    Affects Versions: 2.0.5
>            Reporter: Justin Piper
>            Priority: Minor
>
> If you try to assign multiple variables from an iterator Groovy will skip 
> every other value.
> Example:
> {code}
> final list = [1,2,3]
> final iter = list.iterator()
> final def (a,b,c) = list
> final def (d,e,f) = iter
> assert "$a $b $c" == "$d $e $f"
> {code}
> Result:
> {noformat}
> Assertion failed: 
> assert "$a $b $c" == "$d $e $f"
>          |  |  |  |    |  |  |
>          1  2  3  |    1  3  null
>                   false
> {noformat}
> The expected behavior is either that the assertion succeeds, or the 
> assignment to (d,e,f) fails outright.
> If this is fixed it would also be nice if any Iterable could be used on the 
> RHS.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to