Class: Endless

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/tarpaulin/endless.rb

Instance Method Summary collapse

Constructor Details

#initializeEndless

Returns a new instance of Endless.



9
10
11
# File 'lib/tarpaulin/endless.rb', line 9

def initialize
  make_a_promise Lazy.promise &Proc.new
end

Instance Method Details

#eachObject



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/tarpaulin/endless.rb', line 21

def each
  p = get_promise
  a = []
  while p
    car, cdr = p
    head_by_tail = car[1]
    a << head_by_tail
    yield head_by_tail
    p = cdr.get_promise
  end
  a
end

#get_promiseObject



17
18
19
# File 'lib/tarpaulin/endless.rb', line 17

def get_promise
  @p
end

#make_a_promise(p) ⇒ Object



13
14
15
# File 'lib/tarpaulin/endless.rb', line 13

def make_a_promise(p)
  @p = p
end

#mapObject



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/tarpaulin/endless.rb', line 34

def map
  p = get_promise
  a = []
  while p
    car, cdr = p
    head_by_tail = car[1]
    a << (yield head_by_tail)
    p = cdr.get_promise
  end
  a
end