Feature #2832

Vector#each and Enumerable

Added by Marc-Andre Lafortune about 4 years ago. Updated over 1 year ago.

[ruby-core:28405]
Status:Closed
Priority:Normal
Assignee:Marc-Andre Lafortune
Category:lib
Target version:next minor

Description

=begin
Vector should implement #each and include Enumerable, since it is so Array-like.

Enumerable methods that return an array should probably be specialized to return a Vector (e.g. map, first, ...)

See also ,
=end

History

#1 Updated by Yukihiro Matsumoto about 4 years ago

  • Status changed from Open to Closed
  • % Done changed from 0 to 100

=begin
This issue was solved with changeset r26801.
Marc-Andre, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.

=end

#2 Updated by Marc-Andre Lafortune about 4 years ago

  • Status changed from Closed to Open

=begin
Thanks Matz.

Vector#map/collect should return Vector, no?

I'm fine with the others methods, like #drop(while), #find(all), #first, returning arrays though.
=end

#3 Updated by Yukihiro Matsumoto about 4 years ago

=begin
Hi,

In message "Re: Feature #2832 Vector#each and Enumerable"
on Tue, 9 Mar 2010 13:29:03 +0900, Marc-Andre Lafortune redmine@ruby-lang.org writes:

|Vector#map/collect should return Vector, no?

I don't think so. It returns a collection of values given from the
block. Array is a representation of collection. Matrix#collect
now returns Matrix, but I consider it caused by misunderstanding.

                        matz.

=end

#4 Updated by Marc-Andre Lafortune about 4 years ago

  • Assignee changed from Keiju Ishitsuka to Marc-Andre Lafortune

=begin

=end

#5 Updated by Marc-Andre Lafortune about 4 years ago

=begin
I'm probably crazy, and I must be the only one wishing this, but I wish that #collect was used to collect elements (and always returned an array), while #map was used to map an object by applying a functor to its element (and returned the original class when possible, like Set, Matrix, ...)

=end

#6 Updated by Benoit Daloze about 4 years ago

=begin

I'm probably crazy, and I must be the only one wishing this, but I wish
that #collect was used to collect elements (and always returned an array),
while #map was used to map an object by applying a functor to its element
(and returned the original class when possible, like Set, Matrix, ...)

I think Vector#to_a#map is better than Vector#collect, since it's far more
explicit for that purpose

I agree with the fact methods like map should return their own kind of
Enumerable (for example sorting a Hash result in ... an Array)

I'm probably crazy, and I must be the only one wishing this, but I wish that #collect was used to collect elements (and always returned an array), while #map was used to map an object by applying a functor to its element (and returned the original class when possible, like Set, Matrix, ...)

I think Vector#to_a#map is better than Vector#collect, since it's far more explicit for that purposeI agree with the fact methods like map should return their own kind of Enumerable (for example sorting a Hash result in ... an Array)

=end

#7 Updated by Kazuhiro NISHIYAMA about 4 years ago

  • Target version changed from 1.9.2 to 2.0.0

=begin

=end

#8 Updated by Shyouhei Urabe over 3 years ago

  • Status changed from Open to Assigned

=begin

=end

#9 Updated by Koichi Sasada over 1 year ago

  • Description updated (diff)

ping. status?

#10 Updated by Yusuke Endoh over 1 year ago

  • Target version changed from 2.0.0 to next minor

Marc-Andre, what do we have to do about this ticket?
I'm setting to next minor. Let me know if there is any task for 2.0.0.

Yusuke Endoh mame@tsg.ne.jp

#11 Updated by Marc-Andre Lafortune over 1 year ago

  • Status changed from Assigned to Closed

Right, let's close this.

I still think that Vector#map & select be covariant, and I'll change them if ever there's a request to second that.

Also available in: Atom PDF