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/behavior.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: Behavior, Delayed, Empty
Constant Summary
collapse
- ConstraintError =
Class.new RuntimeError
- EmptyStream =
empty_stream
- Version =
"0.3.1"
- IllegalState =
Class.new RuntimeError
Instance Attribute Summary collapse
Instance Method Summary
collapse
iterate
#__combine__, #combine, #split_into
Methods included from Enumerable
#__drop_while__, #__filter__, #__flatmap__, #__flatmap_with_each__, #__inject__, #__inject_while__, #__lazy_take__, #__lazy_take_until__, #__lazy_take_while__, #__map__, #__scan__, #__take_while__, #__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.
19
20
21
|
# File 'lib/lab42/stream.rb', line 19
def head
@head
end
|
#promise ⇒ Object
Returns the value of attribute promise.
19
20
21
|
# File 'lib/lab42/stream.rb', line 19
def promise
@promise
end
|
Instance Method Details
#__combine_streams__(op, args) ⇒ Object
53
54
55
56
57
58
|
# File 'lib/lab42/stream.rb', line 53
def __combine_streams__ op, args
return empty_stream if args.any?(&:empty?)
new_head = op.(head, *args.map(&:head))
cons_stream( new_head ){ tail.__combine_streams__(op, args.map(&:tail)) }
end
|
#append(other) ⇒ Object
Also known as:
+
22
23
24
25
|
# File 'lib/lab42/stream.rb', line 22
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
29
30
31
32
33
|
# File 'lib/lab42/stream.rb', line 29
def combine_streams *args, &operation
op = args.shift unless self.class === args.first
raise ArgumentError, "Missing stream parameters" if args.empty?
__combine_streams__ Behavior.make( op, &operation), args
end
|
#drop(n = 1) ⇒ Object
35
36
37
38
39
40
41
42
43
|
# File 'lib/lab42/stream.rb', line 35
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
45
|
# File 'lib/lab42/stream.rb', line 45
def empty?; false end
|
#tail ⇒ Object
47
48
49
|
# File 'lib/lab42/stream.rb', line 47
def tail
promise.()
end
|
#to_stream ⇒ Object
51
|
# File 'lib/lab42/stream.rb', line 51
def to_stream; self end
|