From: "marcandre (Marc-Andre Lafortune)" Date: 2013-01-14T13:26:53+09:00 Subject: [ruby-core:51417] [ruby-trunk - Bug #7690] Enumerable::Lazy#flat_map should not call each Issue #7690 has been updated by marcandre (Marc-Andre Lafortune). PS: The only duck typing I can think of is `respond_to?(:each) && respond_to?(:force)`; not sure if that's much better though. ---------------------------------------- Bug #7690: Enumerable::Lazy#flat_map should not call each https://bugs.ruby-lang.org/issues/7690#change-35396 Author: marcandre (Marc-Andre Lafortune) Status: Assigned Priority: High Assignee: shugo (Shugo Maeda) 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/