lib/arc-furnace/unfold.rb in arc-furnace-0.1.3 vs lib/arc-furnace/unfold.rb in arc-furnace-0.1.4

- old
+ new

@@ -5,28 +5,30 @@ # rows and whatnot. Only #unfold is required for implementation. module ArcFurnace class Unfold < Source private_attr_reader :source, :unfolded - attr_reader :value def initialize(source:) @source = source - advance + @value = nil end - def prepare - source.prepare + def value + if @value.nil? && !empty? + advance + end + @value end # Given a row from the source, produce the unfolded rows as a result. This method must return # an array. def unfold(row) raise "Unimplemented!" end def empty? - value.nil? && source.empty? + @value.nil? && source.empty? end def advance while (unfolded.nil? || unfolded.empty?) && !source.empty? # Use reverse since we want to process in-order, but, #pop is much faster than #unshift