Project

General

Profile

Actions

Bug #6155

closed

Enumerable::Lazy#flat_map raises an exception when an element does not respond to #each

Added by dkubb (Dan Kubb) almost 13 years ago. Updated over 12 years ago.

Status:
Closed
Target version:
ruby -v:
ruby 2.0.0dev (2012-03-15 trunk 35028) [x86_64-darwin11.3.0]
Backport:
[ruby-core:43334]

Description

The following statement will raise "NoMethodError: undefined method `each' for 1:Fixnum":

[1, 2, 3].lazy.flat_map { |n| n }.to_a

It appears as if Enumerable::Lazy#flat_map is calling #each on every element, regardless of whether it can work or not.

As a reference, the equivalent statement using Enumerable#flat_map works:

[1, 2, 3].flat_map { |n| n }.to_a

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0