Class: CallableTree::Node::Internal::Strategy::Broadcast
- Inherits:
-
Object
- Object
- CallableTree::Node::Internal::Strategy::Broadcast
- Includes:
- CallableTree::Node::Internal::Strategy
- Defined in:
- lib/callable_tree/node/internal/strategy/broadcast.rb
Instance Method Summary collapse
- #call(nodes, *inputs, **options) ⇒ Object
-
#initialize(terminable: false) ⇒ Broadcast
constructor
A new instance of Broadcast.
Methods included from CallableTree::Node::Internal::Strategy
#==, #eql?, #hash, #name, #terminable?
Constructor Details
#initialize(terminable: false) ⇒ Broadcast
10 11 12 13 14 15 16 17 18 |
# File 'lib/callable_tree/node/internal/strategy/broadcast.rb', line 10 def initialize(terminable: false) self.terminable = terminable @terminator = if terminable proc { |node, output, *inputs, **| node.terminate?(output, *inputs, **) } else proc { false } end end |
Instance Method Details
#call(nodes, *inputs, **options) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/callable_tree/node/internal/strategy/broadcast.rb', line 20 def call(nodes, *inputs, **) nodes.reduce([]) do |outputs, node| output = (node.call(*inputs, **) if node.match?(*inputs, **)) outputs << output if @terminator.call(node, output, *inputs, **) break outputs else outputs end end end |