Class: Turbine::Pipeline::Also

Inherits:
Split show all
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

#source

Instance Method Summary collapse

Methods inherited from Split

#trace, #tracing=

Methods inherited from Expander

#next

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