-
Notifications
You must be signed in to change notification settings - Fork 157
Description
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).