Class: Pipetree::Railway

Inherits:
Object
  • Object
show all
Includes:
Inspect, Add
Defined in:
lib/pipetree/railway/operator.rb,
lib/pipetree/railway.rb

Overview

Optimize the most common steps with Stay/And objects that are faster than procs. This is experimental API and might be removed/changed without prior warning.

Defined Under Namespace

Modules: Add, Inspect, Operator Classes: And, On, Stay, Strut

Constant Summary collapse

Track =

Tracks emitted by steps.

Class.new
Left =
Class.new(Track)
Right =
Class.new(Track)

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Inspect

#inspect, #inspect_func, #inspect_line, #inspect_row, #inspect_rows

Methods included from Add

#add

Constructor Details

#initialize(*args) ⇒ Railway

Returns a new instance of Railway.



6
7
8
9
10
# File 'lib/pipetree/railway.rb', line 6

def initialize(*args)
  @steps   = Array.new(*args)
  @index   = Hash.new
  @inspect = Hash.new
end

Class Method Details

.&(proc) ⇒ Object



22
23
24
# File 'lib/pipetree/railway/operator.rb', line 22

def self.&(proc)
  On.new(Right, And.new(proc))
end

.<(proc) ⇒ Object



18
19
20
# File 'lib/pipetree/railway/operator.rb', line 18

def self.<(proc)
  On.new(Left, Stay.new(proc))
end

.>(proc) ⇒ Object



26
27
28
# File 'lib/pipetree/railway/operator.rb', line 26

def self.>(proc)
  On.new(Right, Stay.new(proc))
end

Instance Method Details

#call(input, options) ⇒ Object

Actual implementation of Pipetree:Railway. Yes, it’s that simple!



13
14
15
16
17
18
19
# File 'lib/pipetree/railway.rb', line 13

def call(input, options)
  input = [Right, input]

  @steps.inject(input) do |(last, memo), step|
    step.call(last, memo, options)
  end
end