Class: Turbine::Pipeline::Also
- Defined in:
- lib/turbine/pipeline/split.rb
Overview
A special case of split which emits the input value, and the results of a the given branches.
For example
# Get your friends and their friends, and emit both as a single list.
nodes.out(:friend).also(->(node) { node.out(:friend) })
Instance Attribute Summary
Attributes inherited from Segment
Instance Method Summary collapse
-
#initialize(*branches, &block) ⇒ Also
constructor
Creates a new Also segment.
Methods inherited from Split
Methods inherited from Expander
Methods inherited from Segment
#append, #each, #inspect, #next, #rewind, #to_s, #trace, #tracing=
Constructor Details
#initialize(*branches, &block) ⇒ Also
Creates a new Also segment.
branches - A single branch whose results will be emitted along with
the input value.
For example
nodes.also(->(n) { n.out(:spouse) }, ->(n) { n.out(:child) })
If you only need to supply a single branch, you can pass it as a block instead of a proc wrapped in an array.
nodes.also { |n| n.out(:spouse) }
Returns a new Also.
127 128 129 |
# File 'lib/turbine/pipeline/split.rb', line 127 def initialize(*branches, &block) super(*[->(node) { node }, *branches, block].compact) end |