Class: Marso::FiberFilter
- Defined in:
- lib/marso/toolbelt/fiberpiping.rb
Constant Summary
Constants inherited from Enumerate
Instance Attribute Summary
Attributes inherited from Enumerate
Instance Method Summary collapse
-
#initialize(process, source = {}) ⇒ FiberFilter
constructor
A new instance of FiberFilter.
- #resume ⇒ Object
- #source(other_source) ⇒ Object
Methods inherited from Enumerate
#clone, #execute, from, #select, #select_many, #to_a, #where, #|
Constructor Details
#initialize(process, source = {}) ⇒ FiberFilter
Returns a new instance of FiberFilter.
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 |
# File 'lib/marso/toolbelt/fiberpiping.rb', line 174 def initialize(process, source={}) @src = source @process = process @fiber_delegate = Fiber.new do output = nil while input = Fiber.yield(output) if process.call(input) output = input else output = :invalid_input end end end @fiber_delegate.resume end |
Instance Method Details
#resume ⇒ Object
192 193 194 195 196 197 198 199 200 201 |
# File 'lib/marso/toolbelt/fiberpiping.rb', line 192 def resume v = nil if @src.is_a?(Marso::Enumerate) v = @fiber_delegate.resume(@src.resume) v = self.resume if v == :invalid_input else v = @fiber_delegate.resume end return v end |
#source(other_source) ⇒ Object
203 204 205 |
# File 'lib/marso/toolbelt/fiberpiping.rb', line 203 def source(other_source) FiberFilter.new(@process, other_source) end |