groovy icon indicating copy to clipboard operation
groovy copied to clipboard

GROOVY-5744, GROOVY-10666: multi-assign via `iterator()` or `getAt(int)`

Open eric-milles opened this issue 3 years ago • 2 comments

Support multi-assign for Stream and Iterator. Improve efficiency of multi-assign for types that do not support direct indexing like Set.

Translate "def (one,two) = rhs" into (pseudo-code):

def one, two;
{
  def iter = rhs.iterator(), first;
  if (iter.hasNext() && (first = iter.next()) !== rhs) {
    one = first
    two = iter.hasNext() ? iter.next() : null
  } else {
    one = rhs.getAt(0)
    two = rhs.getAt(1)
  }
}

https://issues.apache.org/jira/browse/GROOVY-10666 https://issues.apache.org/jira/browse/GROOVY-5744

eric-milles avatar Aug 01 '22 02:08 eric-milles

I don't see changes from double quotes to single quotes as formatting change, nor do I see a change from {} to {->} as such a change. So where any of these changes required for this code change to pass?

blackdrag avatar Aug 04 '22 14:08 blackdrag

On my list to look at tomorrow.

paulk-asert avatar Aug 14 '22 14:08 paulk-asert

Merged. Thanks.

daniellansun avatar Oct 10 '22 08:10 daniellansun

I'll probably revert this, I have an alternative implementation which I have spoken to Eric about but I have been too busy with ApacheCon to get my PR ready for review.

paulk-asert avatar Oct 10 '22 09:10 paulk-asert

Got it.

daniellansun avatar Oct 10 '22 09:10 daniellansun

@paulk-asert Instead of revert, can you just replace the "multiple declaration or assignment" block? There are some other fixups, including new test cases that I'd like to keep.

eric-milles avatar Oct 10 '22 15:10 eric-milles

@eric-milles I'll see what I can do.

paulk-asert avatar Oct 10 '22 19:10 paulk-asert