ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:38154] [Ruby 1.9 - Feature #5044][Open] #zip with block return mapped results
@ 2011-07-18  3:35 Thomas Sawyer
  2011-07-18 13:29 ` [ruby-core:38165] [Ruby 1.9 - Feature #5044] " Benoit Daloze
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: Thomas Sawyer @ 2011-07-18  3:35 UTC (permalink / raw
  To: ruby-core


Issue #5044 has been reported by Thomas Sawyer.

----------------------------------------
Feature #5044: #zip with block return mapped results
http://redmine.ruby-lang.org/issues/5044

Author: Thomas Sawyer
Status: Open
Priority: Normal
Assignee: 
Category: 
Target version: 


Is there any reason that #zip doesn't return results like map?

  [1,2,3].zip([1,2,3]){ |a,b| a + b }  #=> [2,4,6]

Currently, it just returns nil, which seems rather contrary to the return result of the non-block form.



-- 
http://redmine.ruby-lang.org

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [ruby-core:38165] [Ruby 1.9 - Feature #5044] #zip with block return mapped results
  2011-07-18  3:35 [ruby-core:38154] [Ruby 1.9 - Feature #5044][Open] #zip with block return mapped results Thomas Sawyer
@ 2011-07-18 13:29 ` Benoit Daloze
  2012-03-25  8:03 ` [ruby-core:43653] [ruby-trunk - Feature #5044][Assigned] " mame (Yusuke Endoh)
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Benoit Daloze @ 2011-07-18 13:29 UTC (permalink / raw
  To: ruby-core


Issue #5044 has been updated by Benoit Daloze.


Hi,

Please have a look at http://redmine.ruby-lang.org/issues/4539 (or [ruby-core:35613]).

The reason is explained by Yusuke in [ruby-core:35682]:

>2011/4/5 Benoit Daloze <eregontp@gmail.com>:
>> An unconditional nil is anyway not useful here, the only concern I see
>> might be the cost of creating this Array.
>
>It is actually a problem.
>I have used Array#zip with block for iteration many times.
>
> big_ary1.zip(big_ary2) do |x, y|
>   p [x, y]
> end
>
>The change requires some people (including me) to *rewrite*
>such a code as follows:
>
> big_ary1.size.times do |i|
>   x, y = big_ary1[i], big_ary2[i]
>   ...
> end
>
>So I like zip_with, if it is really needed.

That issue kind of got lost, it is probably a good idea to continue it.

For your example, we could have [1,2,3].zip_with([1,2,3], :+)
----------------------------------------
Feature #5044: #zip with block return mapped results
http://redmine.ruby-lang.org/issues/5044

Author: Thomas Sawyer
Status: Open
Priority: Normal
Assignee: 
Category: 
Target version: 


Is there any reason that #zip doesn't return results like map?

  [1,2,3].zip([1,2,3]){ |a,b| a + b }  #=> [2,4,6]

Currently, it just returns nil, which seems rather contrary to the return result of the non-block form.



-- 
http://redmine.ruby-lang.org

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [ruby-core:43653] [ruby-trunk - Feature #5044][Assigned] #zip with block return mapped results
  2011-07-18  3:35 [ruby-core:38154] [Ruby 1.9 - Feature #5044][Open] #zip with block return mapped results Thomas Sawyer
  2011-07-18 13:29 ` [ruby-core:38165] [Ruby 1.9 - Feature #5044] " Benoit Daloze
@ 2012-03-25  8:03 ` mame (Yusuke Endoh)
  2012-03-25  8:03 ` [ruby-core:43654] [ruby-trunk - Feature #5044] " akr (Akira Tanaka)
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: mame (Yusuke Endoh) @ 2012-03-25  8:03 UTC (permalink / raw
  To: ruby-core


Issue #5044 has been updated by mame (Yusuke Endoh).

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


----------------------------------------
Feature #5044: #zip with block return mapped results
https://bugs.ruby-lang.org/issues/5044#change-25153

Author: trans (Thomas Sawyer)
Status: Assigned
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: 
Target version: 


Is there any reason that #zip doesn't return results like map?

  [1,2,3].zip([1,2,3]){ |a,b| a + b }  #=> [2,4,6]

Currently, it just returns nil, which seems rather contrary to the return result of the non-block form.



-- 
http://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [ruby-core:43654] [ruby-trunk - Feature #5044] #zip with block return mapped results
  2011-07-18  3:35 [ruby-core:38154] [Ruby 1.9 - Feature #5044][Open] #zip with block return mapped results Thomas Sawyer
  2011-07-18 13:29 ` [ruby-core:38165] [Ruby 1.9 - Feature #5044] " Benoit Daloze
  2012-03-25  8:03 ` [ruby-core:43653] [ruby-trunk - Feature #5044][Assigned] " mame (Yusuke Endoh)
@ 2012-03-25  8:03 ` akr (Akira Tanaka)
  2012-11-20 12:46 ` [ruby-core:49720] " mame (Yusuke Endoh)
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: akr (Akira Tanaka) @ 2012-03-25  8:03 UTC (permalink / raw
  To: ruby-core


Issue #5044 has been updated by akr (Akira Tanaka).


Currently it can be implemented as follows.

  % ruby -e 'p [1,2,3].zip([1,2,3]).map {|a,b| a + b }'
  [2, 4, 6]
  % ruby -e 'p [1,2,3].lazy.zip([1,2,3]).map {|a,b| a + b }.to_a'
  [2, 4, 6]

----------------------------------------
Feature #5044: #zip with block return mapped results
https://bugs.ruby-lang.org/issues/5044#change-25152

Author: trans (Thomas Sawyer)
Status: Open
Priority: Normal
Assignee: 
Category: 
Target version: 


Is there any reason that #zip doesn't return results like map?

  [1,2,3].zip([1,2,3]){ |a,b| a + b }  #=> [2,4,6]

Currently, it just returns nil, which seems rather contrary to the return result of the non-block form.



-- 
http://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [ruby-core:49720] [ruby-trunk - Feature #5044] #zip with block return mapped results
  2011-07-18  3:35 [ruby-core:38154] [Ruby 1.9 - Feature #5044][Open] #zip with block return mapped results Thomas Sawyer
                   ` (2 preceding siblings ...)
  2012-03-25  8:03 ` [ruby-core:43654] [ruby-trunk - Feature #5044] " akr (Akira Tanaka)
@ 2012-11-20 12:46 ` mame (Yusuke Endoh)
  2018-02-20  8:47 ` [ruby-core:85684] [Ruby trunk Feature#5044][Rejected] " matz
  2019-07-28 23:56 ` [ruby-core:93960] [Ruby master Feature#5044] " foldes.laszlo2
  5 siblings, 0 replies; 7+ messages in thread
From: mame (Yusuke Endoh) @ 2012-11-20 12:46 UTC (permalink / raw
  To: ruby-core


Issue #5044 has been updated by mame (Yusuke Endoh).

Target version set to next minor


----------------------------------------
Feature #5044: #zip with block return mapped results
https://bugs.ruby-lang.org/issues/5044#change-33247

Author: trans (Thomas Sawyer)
Status: Assigned
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: 
Target version: next minor


Is there any reason that #zip doesn't return results like map?

  [1,2,3].zip([1,2,3]){ |a,b| a + b }  #=> [2,4,6]

Currently, it just returns nil, which seems rather contrary to the return result of the non-block form.



-- 
http://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [ruby-core:85684] [Ruby trunk Feature#5044][Rejected] #zip with block return mapped results
  2011-07-18  3:35 [ruby-core:38154] [Ruby 1.9 - Feature #5044][Open] #zip with block return mapped results Thomas Sawyer
                   ` (3 preceding siblings ...)
  2012-11-20 12:46 ` [ruby-core:49720] " mame (Yusuke Endoh)
@ 2018-02-20  8:47 ` matz
  2019-07-28 23:56 ` [ruby-core:93960] [Ruby master Feature#5044] " foldes.laszlo2
  5 siblings, 0 replies; 7+ messages in thread
From: matz @ 2018-02-20  8:47 UTC (permalink / raw
  To: ruby-core

Issue #5044 has been updated by matz (Yukihiro Matsumoto).

Status changed from Assigned to Rejected

We cannot change the behavior. The change would increase the memory consumption (and decrease the performance).

Matz.


----------------------------------------
Feature #5044: #zip with block return mapped results
https://bugs.ruby-lang.org/issues/5044#change-70484

* Author: trans (Thomas Sawyer)
* Status: Rejected
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
* Target version: 
----------------------------------------
Is there any reason that #zip doesn't return results like map?

  [1,2,3].zip([1,2,3]){ |a,b| a + b }  #=> [2,4,6]

Currently, it just returns nil, which seems rather contrary to the return result of the non-block form.




-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [ruby-core:93960] [Ruby master Feature#5044] #zip with block return mapped results
  2011-07-18  3:35 [ruby-core:38154] [Ruby 1.9 - Feature #5044][Open] #zip with block return mapped results Thomas Sawyer
                   ` (4 preceding siblings ...)
  2018-02-20  8:47 ` [ruby-core:85684] [Ruby trunk Feature#5044][Rejected] " matz
@ 2019-07-28 23:56 ` foldes.laszlo2
  5 siblings, 0 replies; 7+ messages in thread
From: foldes.laszlo2 @ 2019-07-28 23:56 UTC (permalink / raw
  To: ruby-core

Issue #5044 has been updated by karatedog (Földes László).


A workaround can be achieved with #then:

`[1,2,3].zip([1,2,3]).then { |a| a.map {|a,b| a+b} }`

Tested in Ruby 2.6.2p47.

----------------------------------------
Feature #5044: #zip with block return mapped results
https://bugs.ruby-lang.org/issues/5044#change-80151

* Author: trans (Thomas Sawyer)
* Status: Rejected
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
* Target version: 
----------------------------------------
Is there any reason that #zip doesn't return results like map?

  [1,2,3].zip([1,2,3]){ |a,b| a + b }  #=> [2,4,6]

Currently, it just returns nil, which seems rather contrary to the return result of the non-block form.




-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2019-07-28 23:56 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-07-18  3:35 [ruby-core:38154] [Ruby 1.9 - Feature #5044][Open] #zip with block return mapped results Thomas Sawyer
2011-07-18 13:29 ` [ruby-core:38165] [Ruby 1.9 - Feature #5044] " Benoit Daloze
2012-03-25  8:03 ` [ruby-core:43653] [ruby-trunk - Feature #5044][Assigned] " mame (Yusuke Endoh)
2012-03-25  8:03 ` [ruby-core:43654] [ruby-trunk - Feature #5044] " akr (Akira Tanaka)
2012-11-20 12:46 ` [ruby-core:49720] " mame (Yusuke Endoh)
2018-02-20  8:47 ` [ruby-core:85684] [Ruby trunk Feature#5044][Rejected] " matz
2019-07-28 23:56 ` [ruby-core:93960] [Ruby master Feature#5044] " foldes.laszlo2

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).