Class: Rivulet::SumStream
Instance Method Summary
collapse
Methods inherited from Stream
#iterate_windows, #max_window, #min_window, #tumbling, #windows
Constructor Details
#initialize(source, mapper: nil) ⇒ SumStream
Returns a new instance of SumStream.
5
6
7
|
# File 'lib/rivulet/sum_stream.rb', line 5
def initialize(source, mapper: nil)
super(mapper ? source.lazy.map(&mapper) : source)
end
|
Instance Method Details
#max_size_while(&rule) ⇒ Object
9
10
11
12
13
|
# File 'lib/rivulet/sum_stream.rb', line 9
def max_size_while(&rule)
best = 0
each_max_window(rule) { |w| best = w.size if w.size > best }
best
end
|
#max_sum_while(&rule) ⇒ Object
15
16
17
18
19
|
# File 'lib/rivulet/sum_stream.rb', line 15
def max_sum_while(&rule)
best = 0
each_max_window(rule) { |w| best = w.sum if w.sum > best }
best
end
|
#min_size_where(&goal) ⇒ Object
21
22
23
24
25
26
27
|
# File 'lib/rivulet/sum_stream.rb', line 21
def min_size_where(&goal)
best = nil
iterate_windows(mode: :satisfied, rule: goal) do |w|
best = w.size if best.nil? || w.size < best
end
best
end
|