Class: Apricot::Cons

Inherits:
Object show all
Includes:
Seq
Defined in:
lib/apricot/cons.rb

Instance Method Summary collapse

Methods included from Seq

#<=>, #cons, #empty?, #hash, #last, #rest, #to_s, #to_seq

Methods included from Enumerable

#to_list

Constructor Details

#initialize(head, tail) ⇒ Cons

Returns a new instance of Cons.



5
6
7
8
# File 'lib/apricot/cons.rb', line 5

def initialize(head, tail)
  @head = head
  @tail = tail.to_seq
end

Instance Method Details

#each {|first| ... } ⇒ Object

Yields:



22
23
24
25
# File 'lib/apricot/cons.rb', line 22

def each
  yield first
  @tail.each {|x| yield x }
end

#firstObject



10
11
12
# File 'lib/apricot/cons.rb', line 10

def first
  @head
end

#nextObject



14
15
16
17
18
19
20
# File 'lib/apricot/cons.rb', line 14

def next
  if @tail
    @tail
  else
    nil
  end
end