Project

General

Profile

Actions

Bug #17216

closed

Enumerator::Chain doesn't support all Enumerator methods

Added by jeremie (Jérémie Laval) over 3 years ago. Updated about 3 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x86_64-darwin19]
[ruby-core:100302]

Description

Despite the fact that Enumerator::Chain (returned by Enumerator#chain) is supposed to inherit from Enumerator, a lot of Enumerator methods do not work on a chain instance throwing the following error:

TypeError (wrong argument type chain (expected enumerator))

The following code exhibit the problem:

[1, 2, 3].chain([4, 5, 6]).with_index.to_a

A workaround is to use each (also work with map, to_enum, and others) to force a conversion back to a plain enumerator which seems superfluous:

[1, 2, 3].chain([4, 5, 6]).each.with_index.to_a

Related issues 1 (0 open1 closed)

Has duplicate Ruby master - Feature #17347: Enumerator::Chain of Enumerator::Lazy should be lazyClosedActions

Updated by jeremyevans0 (Jeremy Evans) over 3 years ago

I agree that calling the methods directly should work. I've submitted a pull request to internally wrap the Enumerator::Chain in an Enumerator so it doesn't raise TypeError: https://github.com/ruby/ruby/pull/3811

Actions #2

Updated by nobu (Nobuyoshi Nakada) over 3 years ago

  • Has duplicate Feature #17347: Enumerator::Chain of Enumerator::Lazy should be lazy added
Actions #3

Updated by jeremyevans (Jeremy Evans) about 3 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]

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0