class Immutable::Splitter

This class can divide a list up into 2 `List`s, one for the prefix of elements for which the block returns true, and another for all the elements after that. It guarantees that 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/immutable/list.rb, line 1486
def initialize(list, block)
  @list, @block, @left, @right = list, block, [], EmptyList
end

Public Instance Methods

done?() click to toggle source
# File lib/immutable/list.rb, line 1503
def done?
  @list.empty?
end
next_item() click to toggle source
# File lib/immutable/list.rb, line 1490
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