Forum: Ruby-core [ruby-trunk - Feature #8371][Open] Make some enumerators mimic arrays

Fe1c0797f345249625590d25a51efd0a?d=identicon&s=25 prijutme4ty (Ilya Vorontsov) (Guest)
on 2013-05-05 21:26
(Received via mailing list)
Issue #8371 has been reported by prijutme4ty (Ilya Vorontsov).

----------------------------------------
Feature #8371: Make some enumerators mimic arrays
https://bugs.ruby-lang.org/issues/8371

Author: prijutme4ty (Ilya Vorontsov)
Status: Open
Priority: Normal
Assignee:
Category: core
Target version:


Some enumerators yields data by one element so that in some way such
enumerators can be treated as arrays in some ways. But they are still
enumerators, so they doesn't respond to methods each array responds. As
an example, there is code I write from time to time:
'Hello world'.each_char.join("\t") and it fails just because I didn't
use #to_a.
I propose that enumerators have subclasses (I guess simple extending of
enumerator with module can impact perfomance) such as ArrayEnumerator so
that String#each_char and #each_line and so on returned not simple
Enumerator but ArrayEnumerator which will respond #join and #uniq
method.
7fe945668a4fc098e886e20dea71d2ee?d=identicon&s=25 zzak (Zachary Scott) (Guest)
on 2013-06-02 09:11
(Received via mailing list)
Issue #8371 has been updated by zzak (Zachary Scott).

Status changed from Open to Feedback
Assignee set to matz (Yukihiro Matsumoto)

There is a discussion on this on #1666
----------------------------------------
Feature #8371: Make some enumerators mimic arrays
https://bugs.ruby-lang.org/issues/8371#change-39633

Author: prijutme4ty (Ilya Vorontsov)
Status: Feedback
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: core
Target version:


Some enumerators yields data by one element so that in some way such
enumerators can be treated as arrays in some ways. But they are still
enumerators, so they doesn't respond to methods each array responds. As
an example, there is code I write from time to time:
'Hello world'.each_char.join("\t") and it fails just because I didn't
use #to_a.
I propose that enumerators have subclasses (I guess simple extending of
enumerator with module can impact perfomance) such as ArrayEnumerator so
that String#each_char and #each_line and so on returned not simple
Enumerator but ArrayEnumerator which will respond #join and #uniq
method.
This topic is locked and can not be replied to.