Feature #17347
closedEnumerator::Chain of Enumerator::Lazy should be lazy
Description
ruby 2.6.6p146 (2020-03-31 revision 67876) [x86_64-linux]
Consider the following script:
a = [1,2,3].lazy
p a
b = [4,5,6].lazy
p b
c = a + b
p c
This gives the output:
#<Enumerator::Lazy: [1, 2, 3]>
#<Enumerator::Lazy: [4, 5, 6]>
#<Enumerator::Chain: [#<Enumerator::Lazy: [1, 2, 3]>, #<Enumerator::Lazy: [4, 5, 6]>]>
Note that c
is just Enumerator::Chain
; but all its component enumerators are lazy, so it would be nice if c
were lazy.
That is, I'd like the output to be:
#<Enumerator::Lazy: [1, 2, 3]>
#<Enumerator::Lazy: [4, 5, 6]>
#<Enumerator::Lazy: #<Enumerator::Chain: [#<Enumerator::Lazy: [1, 2, 3]>, #<Enumerator::Lazy: [4, 5, 6]>]>>
Updated by nobu (Nobuyoshi Nakada) over 4 years ago
- Is duplicate of Bug #17216: Enumerator::Chain doesn't support all Enumerator methods added
Updated by asilano (Chris Howlett) over 4 years ago
Is it a duplicate? I can see it's similar, but I'm not entirely sure fixing #17216 will fix this. Willing to be wrong, though.
Updated by jeremyevans0 (Jeremy Evans) about 4 years ago
This isn't a duplicate of #17216 even though it is related. I agree that this feature would be useful. I've included an implementation in the same pull request: https://github.com/ruby/ruby/pull/3811
Updated by jeremyevans (Jeremy Evans) about 4 years ago
- Status changed from Open to Closed
Applied in changeset git|bf40fe9fed19a5e22081b133661c0629988f1618.
Fix calling enumerator methods such as with_index on Enumerator::Chain
This previously raised a TypeError. Wrap the Enumerator::Chain in
an Enumerator to work around the problem.
Fixes [Bug #17216]