From: Brian Candler Date: 2009-06-23T04:36:39+09:00 Subject: Re: map shall not return an Enumerator ( was re guru help ) Robert Dober wrote: > I believe that the confusion arises from the fact that map returns an > Enumerator and that just seems quite flawed at second thought (or is > this third thought ;). > > Why the heck does map return an Enumerator? If I wanted that I surely > would have called to_enum ! I agree that map and select returning an Enumerator, in the way they do in 1.8.7/1.9, is pretty pointless. But if map without a block (and select without a block etc) are not useful, but I don't think it helps to overload them in the way you want either. I'd rather get an error raised, as per 1.8.6. Aside: what's more interesting to me is "horizontal" execution of enumerators - that is, passing each value along instead of building intermediate arrays - and thus being able to run map/select on infinite lists. See: http://redmine.ruby-lang.org/issues/show/708 http://redmine.ruby-lang.org/issues/show/707 There's also an implementation of this in the facets library. In this case, if you write infinite.map { |x| x*2 }.select { |x| x % 3 == 0 } ... then an Enumerator is returned at each stage of the chain. However you still need to provide a block to map and a block to select, of course, so it's not the same as #map without block returning an Enumerator. -- Posted via http://www.ruby-forum.com/.