Bug #3525: Enumerable#flat_map does not return a flatted enumerable http://redmine.ruby-lang.org/issues/show/3525 Author: Jan Lelis Status: Open, Priority: Normal Target version: 1.9.2 ruby -v: ruby 1.9.2dev (2010-07-02 revision 28524) [i686-linux] Hi, the new flat_map method does not return flatted enumerables: irb(main):072:0> [[1,2],2,3].flat_map{|e|e} => [1, 2, 2, 3] irb(main):071:0> [[1,2],2,3].flat_map.to_a => [[1, 2], 2, 3]
on 2010-07-02 20:50
on 2010-07-02 22:15
Issue #3525 has been updated by Yusuke Endoh. Status changed from Open to Rejected Hi, 2010/7/3 Jan Lelis <redmine@ruby-lang.org>: > the new flat_map method does not return flatted enumerables: > > irb(main):072:0> [[1,2],2,3].flat_map{|e|e} > => [1, 2, 2, 3] > irb(main):071:0> [[1,2],2,3].flat_map.to_a > => [[1, 2], 2, 3] It is indeed confusing a little, but not a bug. Enumerable#flat_map aggregates values that is returned from block call, and returns a flattend array of these values. Enumerator#to_a aggregates arguments that is passed to (implicit) block and just returns it as an array. Look and consider the result of [[1,2],2,3].reject.to_a. -- Yusuke Endoh <mame@tsg.ne.jp> ---------------------------------------- http://redmine.ruby-lang.org/issues/show/3525
Please log in before posting. Registration is free and takes only a minute.
Existing account
(Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
Log in with Google account | Log in with Yahoo account
No account? Register here.