Class: CallableTree::Node::Internal::Strategy::Seek
- Inherits:
-
Object
- Object
- CallableTree::Node::Internal::Strategy::Seek
- Includes:
- CallableTree::Node::Internal::Strategy
- Defined in:
- lib/callable_tree/node/internal/strategy/seek.rb
Instance Method Summary collapse
- #call(nodes, *inputs, **options) ⇒ Object
-
#initialize(matchable: true, terminable: true) ⇒ Seek
constructor
A new instance of Seek.
Methods included from CallableTree::Node::Internal::Strategy
#==, #eql?, #hash, #matchable?, #name, #terminable?
Constructor Details
#initialize(matchable: true, terminable: true) ⇒ Seek
Returns a new instance of Seek.
10 11 12 13 |
# File 'lib/callable_tree/node/internal/strategy/seek.rb', line 10 def initialize(matchable: true, terminable: true) self.matchable = matchable self.terminable = terminable end |
Instance Method Details
#call(nodes, *inputs, **options) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/callable_tree/node/internal/strategy/seek.rb', line 15 def call(nodes, *inputs, **) nodes .lazy .select { |node| matcher.call(node, *inputs, **) } .map do |node| output = node.call(*inputs, **) terminated = terminator.call(node, output, *inputs, **) [output, terminated] end .select { |_output, terminated| terminated } .map { |output, _terminated| output } .first end |