Class: CallableTree::Node::Internal::Strategy::Seek

Inherits:
Object
  • Object
show all
Includes:
CallableTree::Node::Internal::Strategy
Defined in:
lib/callable_tree/node/internal/strategy/seek.rb

Instance Method Summary collapse

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, **options)
  nodes
    .lazy
    .select { |node| matcher.call(node, *inputs, **options) }
    .map do |node|
      output = node.call(*inputs, **options)
      terminated = terminator.call(node, output, *inputs, **options)
      [output, terminated]
    end
    .select { |_output, terminated| terminated }
    .map { |output, _terminated| output }
    .first
end