ArrayList list = list.add( list.add( list.add( Iterator it = list.iterator(); while Object element = it.next(); System.out.println(element); }; it.next();
def fibonacci(n) a = b = 1 n.times do yield a a, b = b, a + b end end def a = b = n.times a, b = b, a + b end return to_enum(__method__, n) unless block_given?
def fibonacci(n) a = b = 1 n.times do yield a a, b = b, a + b end end def a = b = n.times a, b = b, a + b end fibonacci(7).each { |a| puts a } fibonacci(25).map { |a| a * 3 }.select(&:odd?) fibonacci(100).find { |a| a > 50 } return to_enum(__method__, n) unless block_given? ] [ Enumerable!
static next_i { VALUE nil VALUE result; result next_ii e "iteration reached an end" return } next_i(VALUE curr, VALUE obj) return rb_fiber_yield(1, &nil); enumerator.c Fiber!
class CustomEnumerator def initialize(collection, meth, *args) @collection = collection @fiber = Fiber.new do @collection.send(meth, *args) do |n| Fiber.yield(n) end raise StopIteration end end end class CustomEnumerator def initialize(collection, meth, *args) @collection = collection class CustomEnumerator
class Document def each_line return to_enum(:each_line) unless block_given? # yield each line end def each_word return to_enum(:each_word) unless block_given? # yield each word end def each_para return to_enum(:each_para) unless block_given? # yield each paragraph end end class Document def each_line return to_enum(:each_line) unless block_given? # yield each line end class Document def each_line return to_enum(:each_line) unless block_given? # yield each line end def each_word return to_enum(:each_word) unless block_given? # yield each word end class Document
class BinaryTree def breadth_first return to_enum(__method__) unless block_given? # yield values in “breadth first” order end def pre_order # etc… end def post_order end def in_order end end