Sha256: 54838daee103260e438fc3fc888aab4b48b723bead69b6423f554564f08d6c05

Contents?: true

Size: 710 Bytes

Versions: 5

Compression:

Stored size: 710 Bytes

Contents

# frozen_string_literal: true

require 'callable_tree'

module Node
  class LessThan
    include CallableTree::Node::Internal

    def initialize(num)
      @num = num
    end

    def match?(input)
      super && input < @num
    end
  end
end

tree = CallableTree::Node::Root.new.append(
  Node::LessThan.new(5).append(
    proc { |input| input * 2 }, # anonymous external node
    proc { |input| input + 1 }  # anonymous external node
  ).compose,
  Node::LessThan.new(10).append(
    proc { |input| input * 3 }, # anonymous external node
    proc { |input| input - 1 }  # anonymous external node
  ).compose
).compose

(0..10).each do |input|
  output = tree.call(input)
  puts "#{input} -> #{output}"
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
callable_tree-0.3.4 examples/internal-compose.rb
callable_tree-0.3.3 examples/internal-compose.rb
callable_tree-0.3.2 examples/internal-compose.rb
callable_tree-0.3.1 examples/internal-compose.rb
callable_tree-0.3.0 examples/internal-compose.rb