Based on https://github.com/yhara/enumerable-lazy Inspired by https://github.com/antimon2/enumerable_lz http://jp.rubyist.net/magazine/?0034-Enumerable_lz (ja)
# File mrbgems/mruby-enum-lazy/mrblib/lazy.rb, line 75 def drop(n) dropped = 0 Lazy.new(self){|yielder, val| if dropped < n dropped += 1 else yielder << val end } end
# File mrbgems/mruby-enum-lazy/mrblib/lazy.rb, line 86 def drop_while(&block) dropping = true Lazy.new(self){|yielder, val| if dropping if not block.call(val) yielder << val dropping = false end else yielder << val end } end
# File mrbgems/mruby-enum-lazy/mrblib/lazy.rb, line 124 def flat_map(&block) Lazy.new(self){|yielder, val| ary = block.call(val) # TODO: check ary is an Array ary.each{|x| yielder << x } } end
# File mrbgems/mruby-enum-lazy/mrblib/lazy.rb, line 67 def grep(pattern) Lazy.new(self){|yielder, val| if pattern === val yielder << val end } end
# File mrbgems/mruby-enum-lazy/mrblib/lazy.rb, line 43 def map(&block) Lazy.new(self){|yielder, val| yielder << block.call(val) } end
# File mrbgems/mruby-enum-lazy/mrblib/lazy.rb, line 59 def reject(&block) Lazy.new(self){|yielder, val| if not block.call(val) yielder << val end } end
# File mrbgems/mruby-enum-lazy/mrblib/lazy.rb, line 50 def select(&block) Lazy.new(self){|yielder, val| if block.call(val) yielder << val end } end
# File mrbgems/mruby-enum-lazy/mrblib/lazy.rb, line 100 def take(n) if n == 0 return Lazy.new(self){raise StopIteration} end taken = 0 Lazy.new(self){|yielder, val| yielder << val taken += 1 if taken >= n raise StopIteration end } end
Commenting is here to help enhance the documentation. For example, code samples, or clarification of the documentation.
If you have questions about Ruby or the documentation, please post to one of the Ruby mailing lists. You will get better, faster, help that way.
If you wish to post a correction of the docs, please do so, but also file bug report so that it can be corrected for the next release. Thank you.
If you want to help improve the Ruby documentation, please visit Documenting-ruby.org.