Class: LazyList::Stream
- Inherits:
-
Base
- Object
- Base
- LazyList::Stream
show all
- Defined in:
- lib/lazy_list/stream.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Base
#each, #empty?, #initialize
Constructor Details
This class inherits a constructor from LazyList::Base
Class Method Details
.cycle(a) ⇒ Object
5
6
7
|
# File 'lib/lazy_list/stream.rb', line 5
def cycle(a)
new.prepend(a).recur { |a| a }
end
|
Instance Method Details
#first ⇒ Object
21
22
23
|
# File 'lib/lazy_list/stream.rb', line 21
def first
LazyList.car(@list).call.call
end
|
#inspect ⇒ Object
17
18
19
|
# File 'lib/lazy_list/stream.rb', line 17
def inspect
"[" + take(5).map(&:inspect).join(", ") + "...]"
end
|
#prepend(a) ⇒ Object
10
11
12
13
14
15
|
# File 'lib/lazy_list/stream.rb', line 10
def prepend(a)
@has_contents = true
f = lambda { a }
@list = LazyList.cons f, @list
self
end
|
#recur(&block) ⇒ Object
31
32
33
34
35
|
# File 'lib/lazy_list/stream.rb', line 31
def recur(&block)
@count = Float::INFINITY
@list = _recur( first, &block )
self
end
|
#rest ⇒ Object
25
26
27
|
# File 'lib/lazy_list/stream.rb', line 25
def rest
self.class.new LazyList.cdr(@list).call.call
end
|