Skip to content

Cannot iterate over the result of .values() of ListValue multiple times #1711

@nk-coding

Description

@nk-coding

Hi,
Due to the changes made in #1657, when iterating over the result of .values() of ListValue, only the first iteration actually provides the values, as the iterator is generated when .values() is called, not when the returned Iterable is actually iterated.
All subsequend iterations over the returned result will just contain no entries. This is a change from the previous behavior, and can be somewhat confusing imho.
Technically speaking, this is not a bug, as Iterable does not require that it can be iterated multiple times. However, I do think the current behavior (silent fail) can be confusing and hard to debug, I personally would prefer to either

  • allow iterating over it multiple times
  • or fail with an Exception when iterating over it a second time

A possible implementation for the first option would be moving creating the iterator inside the returned lambda (so that each iteration creates a new Iterator).
I think this would not increase the memory footprint as long as you iterate over the result only one time, and the memory of iterating over the result multiple times should be similar to calling .values() multiple times (which is what you would have to do currently).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions