From: Artem Voroztsov Date: 2008-03-19T03:37:07+09:00 Subject: Re: Questions on Enumerator#skip_first and Enumerable#first I remember Matz talked about LazyArray's in Ruby 2.0 (http://www.ruby-forum.com/topic/129792#579690), which, i guest should solve performance issues of current drop and take. The question is not only in :drop and :take methods, but also in :map, :inject and etc. I prefer method 'Enumerator#map' does not start from the beginning of the collection. In fact I think restarting is not possible for abstract Enumerator. After some (crude, breaking semantics) redefinitions we can compose :take, :drop and :map without creating intermediate arrays. # a.rb class Object def singleton_class class <= 0 @parent.next else raise StopIteration, "Take limit reached" end end end enum end def map(&block) res = [] begin loop {res << block[self.next] } rescue StopIteration=>e; end res end end end p( (1..1000000000).each.drop(2).take(3).map{|i| i} ) $ time ruby_dev a.rb [3, 4, 5] real 0m0.017s user 0m0.006s sys 0m0.002s