Class: Lab42::Stream
- Inherits:
-
Object
show all
- Extended by:
- ClassMethods
- Includes:
- Enumerable, HigherOrder, Utility
- Defined in:
- lib/lab42/stream.rb,
lib/lab42/stream/empty.rb,
lib/lab42/stream/delayed.rb,
lib/lab42/stream/utility.rb,
lib/lab42/stream/version.rb,
lib/lab42/stream/enumerable.rb,
lib/lab42/stream/higher_order.rb,
lib/lab42/stream/class_methods.rb
Defined Under Namespace
Modules: ClassMethods, Enumerable, HigherOrder, Utility
Classes: Delayed, Empty
Constant Summary
collapse
- ConstraintError =
Class.new RuntimeError
- EmptyStream =
empty_stream
- Version =
"0.1.1"
- IllegalState =
Class.new RuntimeError
Instance Attribute Summary collapse
Instance Method Summary
collapse
iterate
#__combine__, #combine, #split_into
Methods included from Enumerable
#__filter__, #__flatmap__, #__flatmap_with_each__, #__inject__, #__inject_while__, #__lazy_take__, #__lazy_take_until__, #__lazy_take_while__, #__map__, #__scan__, #__zip__, #drop_until, #drop_while, #each, #each_without_loops, #filter, #flatmap, #flatmap_with_each, #force_all, #inject, #lazy_take, #lazy_take_until, #lazy_take_while, #make_cyclic, #map, #reduce, #reduce_while, #reject, #scan, #scan1, #take, #take_until, #take_while, #to_a, #zip, #zip_as_ary
Methods included from Utility
#__segment__, #segment, #with_index
Instance Attribute Details
#head ⇒ Object
Also known as:
first
Returns the value of attribute head.
21
22
23
|
# File 'lib/lab42/stream.rb', line 21
def head
@head
end
|
#promise ⇒ Object
Returns the value of attribute promise.
21
22
23
|
# File 'lib/lab42/stream.rb', line 21
def promise
@promise
end
|
Instance Method Details
#__combine_streams__(op, args) ⇒ Object
55
56
57
58
59
60
|
# File 'lib/lab42/stream.rb', line 55
def __combine_streams__ op, args
return empty_stream if args.any?(&sendmsg(:empty?))
new_head = op.(head, *args.map(&sendmsg(:head)))
cons_stream( new_head ){ tail.__combine_streams__(op, args.map(&sendmsg(:tail))) }
end
|
#append(other) ⇒ Object
Also known as:
+
24
25
26
27
|
# File 'lib/lab42/stream.rb', line 24
def append other
raise ArgumentError, "not a stream #{other}" unless self.class === other
cons_stream( head ){ tail.append other }
end
|
#combine_streams(*args, &operation) ⇒ Object
31
32
33
34
35
|
# File 'lib/lab42/stream.rb', line 31
def combine_streams *args, &operation
op = args.shift unless self.class === args.first
raise ArgumentError, "Missing stream parameters" if args.empty?
__combine_streams__ operation.make_behavior( op ), args
end
|
#drop(n = 1) ⇒ Object
37
38
39
40
41
42
43
44
45
|
# File 'lib/lab42/stream.rb', line 37
def drop n = 1
raise ArgumentError, "not a non negative number" if n < 0
t = self
loop do
return t if n.zero?
n -=1
t = t.tail
end
end
|
#empty? ⇒ Boolean
47
|
# File 'lib/lab42/stream.rb', line 47
def empty?; false end
|
#tail ⇒ Object
49
50
51
|
# File 'lib/lab42/stream.rb', line 49
def tail
promise.()
end
|
#to_stream ⇒ Object
53
|
# File 'lib/lab42/stream.rb', line 53
def to_stream; self end
|