class Hamster::Partitioner
@private
At the same time, it guarantees the block will only be called ONCE for each item
for which the block returns true, and another for false
This class can divide a collection into 2 ‘List`s, one of items
def done?
def done? @list.empty? end
def initialize(list, block)
def initialize(list, block) @list, @block, @left, @right = list, block, [], [] end
def next_item
def next_item unless @list.empty? item = @list.head (@block.call(item) ? @left : @right) << item @list = @list.tail end end