class Yadriggy::SourceCode::Cons

@api private

Attributes

head[RW]
tail[RW]

Public Class Methods

append!(lst1, lst2) click to toggle source
# File lib/yadriggy/source_code.rb, line 152
def self.append!(lst1, lst2)
  if lst1 == nil
    lst2
  elsif lst2 == nil
    lst1
  else
    p = lst1
    while p.tail != nil
      p = p.tail
    end
    p.tail = lst2
    lst1
  end
end
list(*elements) click to toggle source
# File lib/yadriggy/source_code.rb, line 144
def self.list(*elements)
  list = nil
  elements.reverse_each do |e|
    list = Cons.new(e, list)
  end
  list
end
new(head, tail=nil) click to toggle source
# File lib/yadriggy/source_code.rb, line 139
def initialize(head, tail=nil)
  @head = head
  @tail = tail
end

Public Instance Methods

each() { |head| ... } click to toggle source
# File lib/yadriggy/source_code.rb, line 177
def each()
  list = self
  while list != nil
    yield list.head
    list = list.tail
  end
end
fold(acc) { |acc, head| ... } click to toggle source
# File lib/yadriggy/source_code.rb, line 185
def fold(acc)
  list = self
  while list != nil
    acc = yield acc, list.head
    list = list.tail
  end
  acc
end
size() click to toggle source
# File lib/yadriggy/source_code.rb, line 167
def size()
  size = 0
  list = self
  while list != nil
    list = list.tail
    size += 1
  end
  size
end