Project

General

Profile

Actions

Feature #3021

closed

Array#product should accept a block.

Added by marcandre (Marc-Andre Lafortune) over 12 years ago. Updated about 11 years ago.

Status:
Closed
Priority:
Normal
Target version:
[ruby-core:29045]

Description

=begin
Array#permutation and #combination will yield to the given block, or else return an enumerator.

I believe Array#product should have been designed the same way.

Returning an enumerator today would break compatibility though.

I suggest that Array#product(&block) yields to the block and returns self. This maintains compatibility while making it possible to produce an enumerable with my_array.to_enum(:product, ...) or to avoid building an intermediate array.

I could implement this feature in time for code freeze.
=end

Actions #1

Updated by mame (Yusuke Endoh) about 12 years ago

  • Assignee set to matz (Yukihiro Matsumoto)

=begin
Hi,

2010/3/27 Marc-Andre Lafortune :

Array#permutation and #combination will yield to the given block, or else return an enumerator.

I believe Array#product should have been designed the same way.

Returning an enumerator today would break compatibility though.

I suggest that Array#product(&block) yields to the block and returns self. This maintains compatibility while making it possible to produce an enumerable with my_array.to_enum(:product, ...) or to avoid building an intermediate array.

Agreed!

In fact, I suggested the similar change to let Array#product
return an Enumerator. [ruby-dev:39277]

Of course, it has a compatibility problem, and matz himself
suggested exactly the same change as you. [ruby-dev:39306]

--
Yusuke ENDOH
=end

Actions #2

Updated by mame (Yusuke Endoh) about 12 years ago

=begin
Hi,

2010/3/31 Yusuke Endoh :

2010/3/27 Marc-Andre Lafortune :

Array#permutation and #combination will yield to the given block, or else return an enumerator.

I believe Array#product should have been designed the same way.

Returning an enumerator today would break compatibility though.

I suggest that Array#product(&block) yields to the block and returns self. This maintains compatibility while making it possible to produce an enumerable with my_array.to_enum(:product, ...) or to avoid building an intermediate array.

Agreed!

In fact, I suggested the similar change to let Array#product
return an Enumerator. ?[ruby-dev:39277]

Of course, it has a compatibility problem, and matz himself
suggested exactly the same change as you. ?[ruby-dev:39306]

Matz agreed with this feature in [ruby-dev:40867]. Thanks!

--
Yusuke ENDOH

=end

Actions #3

Updated by marcandre (Marc-Andre Lafortune) about 12 years ago

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

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

=end

Actions

Also available in: Atom PDF