Feature #2832

Vector#each and Enumerable

Added by Marc-Andre Lafortune almost 2 years ago. Updated 10 months ago.

[ruby-core:28405]
Status:Assigned Start date:03/02/2010
Priority:Normal Due date:
Assignee:Marc-Andre Lafortune % Done:

100%

Category:lib
Target version:2.0.0

Description

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]

Associated revisions

Revision 26801
Added by Yukihiro Matsumoto almost 2 years ago

* lib/matrix.rb (Vector#each): make Vector enumerable. [ruby-core:28405]

Revision 26804
Added by Marc-Andre Lafortune almost 2 years ago

* lib/matrix.rb (Vector#each): Return self and optimization [ruby-core:28405]

History

Updated by Yukihiro Matsumoto almost 2 years ago

  • Status changed from Open to Closed
  • % Done changed from 0 to 100
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.

Updated by Marc-Andre Lafortune almost 2 years ago

  • Status changed from Closed to Open
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.

Updated by Yukihiro Matsumoto almost 2 years ago

Hi,

In message "Re: [ruby-core:28571] [Feature #2832](Open) 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.

Updated by Marc-Andre Lafortune almost 2 years ago

  • Assignee changed from Keiju Ishitsuka to Marc-Andre Lafortune

Updated by Marc-Andre Lafortune almost 2 years ago

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, ...)

Updated by Benoit Daloze almost 2 years ago

>
>
> 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)

<div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><br>
I&#39;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, ...)<br>


<br></blockquote><div><br></div><div>I think Vector#to_a#map is better than Vector#collect, since it&#39;s far more explicit for that purpose</div><div><br></div><div>I agree with the fact methods like map should return their own kind of Enumerable (for example sorting a Hash result in ... an Array)</div>

</div>

Updated by Kazuhiro NISHIYAMA almost 2 years ago

  • Target version changed from 1.9.2 to 2.0.0

Updated by Shyouhei Urabe over 1 year ago

  • Status changed from Open to Assigned

Also available in: Atom PDF