ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:100302] [Ruby master Bug#17216] Enumerator::Chain doesn't support all Enumerator methods
@ 2020-10-05 17:59 jeremie
  2020-11-24 23:13 ` [ruby-core:101060] " merch-redmine
  0 siblings, 1 reply; 2+ messages in thread
From: jeremie @ 2020-10-05 17:59 UTC (permalink / raw
  To: ruby-core

Issue #17216 has been reported by jeremie (Jérémie Laval).

----------------------------------------
Bug #17216: Enumerator::Chain doesn't support all Enumerator methods
https://bugs.ruby-lang.org/issues/17216

* Author: jeremie (Jérémie Laval)
* Status: Open
* Priority: Normal
* ruby -v: ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x86_64-darwin19]
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN
----------------------------------------
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:

```ruby
[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:

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




-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [ruby-core:101060] [Ruby master Bug#17216] Enumerator::Chain doesn't support all Enumerator methods
  2020-10-05 17:59 [ruby-core:100302] [Ruby master Bug#17216] Enumerator::Chain doesn't support all Enumerator methods jeremie
@ 2020-11-24 23:13 ` merch-redmine
  0 siblings, 0 replies; 2+ messages in thread
From: merch-redmine @ 2020-11-24 23:13 UTC (permalink / raw
  To: ruby-core

Issue #17216 has been updated by jeremyevans0 (Jeremy Evans).


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

----------------------------------------
Bug #17216: Enumerator::Chain doesn't support all Enumerator methods
https://bugs.ruby-lang.org/issues/17216#change-88733

* Author: jeremie (Jérémie Laval)
* Status: Open
* Priority: Normal
* ruby -v: ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x86_64-darwin19]
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN
----------------------------------------
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:

```ruby
[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:

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




-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-11-24 23:13 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-10-05 17:59 [ruby-core:100302] [Ruby master Bug#17216] Enumerator::Chain doesn't support all Enumerator methods jeremie
2020-11-24 23:13 ` [ruby-core:101060] " merch-redmine

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).