class Hamster::Partitioner

This class can divide a collection into 2 `List`s, one of items

for which the block returns true, and another for false

At the same time, it guarantees the block will only be called ONCE for each item

@private

Attributes

left[R]
right[R]

Public Class Methods

new(list, block) click to toggle source
# File lib/hamster/list.rb, line 1428
def initialize(list, block)
  @list, @block, @left, @right = list, block, [], []
end

Public Instance Methods

done?() click to toggle source
# File lib/hamster/list.rb, line 1440
def done?
  @list.empty?
end
next_item() click to toggle source
# File lib/hamster/list.rb, line 1432
def next_item
  unless @list.empty?
    item = @list.head
    (@block.call(item) ? @left : @right) << item
    @list = @list.tail
  end
end