Sha256: 7cbb59ce6aada791706725a971a858f5fa9ab3b1d76817d3d9732b03b2ab918e

Contents?: true

Size: 720 Bytes

Versions: 6

Compression:

Stored size: 720 Bytes

Contents

# frozen_string_literal: true

require "dry/logic/operations/binary"
require "dry/logic/result"

module Dry
  module Logic
    module Operations
      class Implication < Binary
        def type
          :implication
        end

        def operator
          :then
        end

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

          if left_result.success?
            right_result = right.(input)
            Result.new(right_result.success?, id) { right_result.to_ast }
          else
            Result::SUCCESS
          end
        end

        def [](input)
          if left[input]
            right[input]
          else
            true
          end
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
dry-logic-1.2.0 lib/dry/logic/operations/implication.rb
dry-logic-1.1.1 lib/dry/logic/operations/implication.rb
dry-logic-1.1.0 lib/dry/logic/operations/implication.rb
dry-logic-1.0.8 lib/dry/logic/operations/implication.rb
grape-extra_validators-2.0.0 vendor/bundle/ruby/2.6.0/gems/dry-logic-1.0.7/lib/dry/logic/operations/implication.rb
dry-logic-1.0.7 lib/dry/logic/operations/implication.rb