Sha256: 7facf0d67e333f004e7b6215d4c69eebc3fb80e0571cd32b60bd66d5fd6eacc2

Contents?: true

Size: 760 Bytes

Versions: 4

Compression:

Stored size: 760 Bytes

Contents

require 'dry/logic/operations/binary'
require 'dry/logic/result'

module Dry
  module Logic
    module Operations
      class And < Binary
        def type
          :and
        end
        alias_method :operator, :type

        def call(input)
          left_result = left.(input)

          if left_result.success?
            right_result = right.(input)

            if right_result.success?
              Result::SUCCESS
            else
              Result.new(false, id) { right_result.ast(input) }
            end
          else
            Result.new(false, id) { [type, [left_result.to_ast, [:hint, right.ast(input)]]] }
          end
        end

        def [](input)
          left[input] && right[input]
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
dry-logic-0.5.0 lib/dry/logic/operations/and.rb
dry-logic-0.4.2 lib/dry/logic/operations/and.rb
dry-logic-0.4.1 lib/dry/logic/operations/and.rb
dry-logic-0.4.0 lib/dry/logic/operations/and.rb