Project

General

Profile

Actions

Feature #2832

closed

Vector#each and Enumerable

Added by marcandre (Marc-Andre Lafortune) over 14 years ago. Updated almost 12 years ago.

Status:
Closed
Target version:
[ruby-core:28405]

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 [ruby-core:28403], [redmine:2831]
=end

Actions #1

Updated by matz (Yukihiro Matsumoto) over 14 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

Actions #2

Updated by marcandre (Marc-Andre Lafortune) over 14 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

Actions #3

Updated by matz (Yukihiro Matsumoto) over 14 years ago

=begin
Hi,

In message "Re: [ruby-core:28571] Feature #2832 Vector#each and Enumerable"
on Tue, 9 Mar 2010 13:29:03 +0900, Marc-Andre Lafortune 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

Actions #4

Updated by marcandre (Marc-Andre Lafortune) over 14 years ago

  • Assignee changed from keiju (Keiju Ishitsuka) to marcandre (Marc-Andre Lafortune)

=begin

=end

Actions #5

Updated by marcandre (Marc-Andre Lafortune) over 14 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

Actions #6

Updated by Eregon (Benoit Daloze) over 14 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)
=end

Actions #7

Updated by znz (Kazuhiro NISHIYAMA) over 14 years ago

  • Target version changed from 1.9.2 to 2.0.0

=begin

=end

Actions #8

Updated by shyouhei (Shyouhei Urabe) about 14 years ago

  • Status changed from Open to Assigned

=begin

=end

Updated by ko1 (Koichi Sasada) about 12 years ago

  • Description updated (diff)

ping. status?

Updated by mame (Yusuke Endoh) almost 12 years ago

  • Target version changed from 2.0.0 to 2.6

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

Updated by marcandre (Marc-Andre Lafortune) almost 12 years 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.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0