Project

General

Profile

Actions

Bug #14495

closed

Enumerator::Lazy#uniq invalid state

Added by chopraanmol1 (Anmol Chopra) about 6 years ago. Updated over 5 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 2.5.0preview1 (2017-10-10 trunk 60153) [x86_64-linux]
[ruby-core:85646]

Description

Currently

2.5.0-preview1 :001 > arr = (0..100).lazy.uniq{|i| i % 10}
 => #<Enumerator::Lazy: #<Enumerator::Lazy: 0..100>:uniq> 
2.5.0-preview1 :002 > arr.to_a
 => [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] 
2.5.0-preview1 :003 > arr.to_a
 => [] 

Expected

2.5.0-preview1 :001 > arr = (0..100).lazy.uniq{|i| i % 10}
 => #<Enumerator::Lazy: #<Enumerator::Lazy: 0..100>:uniq> 
2.5.0-preview1 :002 > arr.to_a
 => [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] 
2.5.0-preview1 :003 > arr.to_a
 => [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] 

Solution Enumerator::Lazy#uniq's hash should be accessed from yielder memo

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0