class Hamster::Splitter
@private
item
after that. It guarantees that the block will only be called ONCE for each
elements for which the block returns true, and another for all the elements
This class can divide a list up into 2 ‘List`s, one for the prefix of
def done?
def done? @list.empty? end
def initialize(list, block)
def initialize(list, block) @list, @block, @left, @right = list, block, [], EmptyList end
def next_item
def next_item unless @list.empty? item = @list.head if @block.call(item) @left << item @list = @list.tail else @right = @list @list = EmptyList end end end