From: "marcandre (Marc-Andre Lafortune)" Date: 2013-01-13T11:30:42+09:00 Subject: [ruby-core:51401] [ruby-trunk - Bug #7690][Open] Enumerable::Lazy#flat_map should not call each Issue #7690 has been reported by marcandre (Marc-Andre Lafortune). ---------------------------------------- Bug #7690: Enumerable::Lazy#flat_map should not call each https://bugs.ruby-lang.org/issues/7690 Author: marcandre (Marc-Andre Lafortune) Status: Open Priority: Normal Assignee: Category: core Target version: 2.0.0 ruby -v: r38794 I would expect that array.flat_map{...} == array.lazy.flat_map{...}.force This is not always the case: [1].flat_map{|i| {i => i} } # => [{1 => 1}], ok [1].lazy.flat_map{|i| {i => i} }.force # => [[1, 1]], expected [{1 => 1}] Note that Matz confirmed that it is acceptable to return straight objects instead of arrays for flat_map [ruby-core:43365] It looks like this was intended for nested lazy enumerators: [1].lazy.flat_map{|i| [i].lazy }.force # => [1] I don't think that's the correct result, and it is different from a straight flat_map: [1].flat_map{|i| [i].lazy } # => [#] This is caused by Lazy#flat_map calls each (while Enumerable#flat_map only looks for Arrays/object responding to to_ary). -- http://bugs.ruby-lang.org/