Actions
Bug #10534
closedEnumerator methods other than "next" do not always respect "peek"
Status:
Rejected
Assignee:
-
Target version:
-
ruby -v:
ruby 2.1.5p273 (2014-11-13 revision 48405) [x86_64-darwin14.0]
Backport:
Description
It seems like using "peek" and then calling other methods on the Enumerator consumes the value that was peeked at. While next
correctly returns the peeked-at value the next time it is called, other Enumerator methods such as to_a
and each
do not.
>> enum = StringIO.new("foo").each
=> #<Enumerator: #<StringIO:0x007ff3313d8688>:each>
>> enum.peek
=> "foo"
>> enum.to_a
=> []
Here the final call to enum.to_a
should have returned ["foo"]
, since we have not consumed anything from the enumerator yet. The peeked-at value is not included in the returned Array.
Taking a glance at the code, it seems that these methods do not call next
under the hood, but instead have some other mechanism of iterating over the Enumerator, this seems very counter-intuitive to me.
Actions
Like0
Like0Like0Like0