Class: Fall::StreamOperation

Inherits:
Object
  • Object
show all
Defined in:
lib/fall/stream_operation.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(func) ⇒ StreamOperation

Returns a new instance of StreamOperation.



14
15
16
# File 'lib/fall/stream_operation.rb', line 14

def initialize(func)
  @func = func
end

Instance Attribute Details

#funcObject (readonly)

Returns the value of attribute func.



3
4
5
# File 'lib/fall/stream_operation.rb', line 3

def func
  @func
end

Class Method Details

.from_code(code) ⇒ Object



5
6
7
8
9
10
11
12
# File 'lib/fall/stream_operation.rb', line 5

def self.from_code(code)
  func = instance_eval <<~RUBY
    proc do |stream|
      #{code}
    end
  RUBY
  new(func)
end

Instance Method Details

#add_to_pipeline(pipeline) ⇒ Object



18
19
20
# File 'lib/fall/stream_operation.rb', line 18

def add_to_pipeline(pipeline)
  pipeline.add_stream_operation(self)
end

#call(stream) ⇒ Object



26
27
28
29
30
31
# File 'lib/fall/stream_operation.rb', line 26

def call(stream)
  stream.map { Record.wrap(_1) }
        .then {
          @func.call(_1)
        }
end

#chain(operation) ⇒ Object



33
34
35
36
37
38
# File 'lib/fall/stream_operation.rb', line 33

def chain(operation)
  identity = ->(i) { i }

  composed = (func >> (operation.func >> identity))
  self.class.new(composed)
end

#to_procObject



22
23
24
# File 'lib/fall/stream_operation.rb', line 22

def to_proc
  @func
end