Polylithic linked list structure used to implement several data structures in Rake.
Cons a new head onto the tail list.
# File rake/linked_list.rb, line 70 def self.cons(head, tail) new(head, tail) end
The standard empty list class for the given LinkedList class.
# File rake/linked_list.rb, line 75 def self.empty self::EMPTY end
Lists are structurally equivalent.
# File rake/linked_list.rb, line 27 def ==(other) current = self while ! current.empty? && ! other.empty? return false if current.head != other.head current = current.tail other = other.tail end current.empty? && other.empty? end
Polymorphically add a new element to the head of a list. The type of head node will be the same list type as the tail.
# File rake/linked_list.rb, line 17 def conj(item) self.class.cons(item, self) end
For each item in the list.
# File rake/linked_list.rb, line 50 def each current = self while ! current.empty? yield(current.head) current = current.tail end self end
Is the list empty?
# File rake/linked_list.rb, line 22 def empty? false end
Commenting is here to help enhance the documentation. For example, code samples, or clarification of the documentation.
If you have questions about Ruby or the documentation, please post to one of the Ruby mailing lists. You will get better, faster, help that way.
If you wish to post a correction of the docs, please do so, but also file bug report so that it can be corrected for the next release. Thank you.
If you want to help improve the Ruby documentation, please visit Documenting-ruby.org.