class Marso::FiberFilter

Public Class Methods

new(process, source={}) click to toggle source
# 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

Public Instance Methods

resume() click to toggle source
# 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) click to toggle source
# File lib/marso/toolbelt/fiberpiping.rb, line 203
def source(other_source)
  FiberFilter.new(@process, other_source)
end