Sha256: c1470196444202ce0ea54ee5167dec19a488686868e443f76001838032451fba

Contents?: true

Size: 719 Bytes

Versions: 5

Compression:

Stored size: 719 Bytes

Contents

# frozen_string_literal: true

require 'dry/logic/operations/unary'
require 'dry/logic/result'

module Dry
  module Logic
    module Operations
      class Each < Unary
        def type
          :each
        end

        def call(input)
          results = input.map { |element| rule.(element) }
          success = results.all?(&:success?)

          Result.new(success, id) do
            failures = results
              .map
              .with_index { |result, idx| [:key, [idx, result.ast(input[idx])]] if result.failure? }
              .compact

            [:set, failures]
          end
        end

        def [](arr)
          arr.map { |input| rule[input] }.all?
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
dry-logic-1.0.6 lib/dry/logic/operations/each.rb
dry-logic-1.0.5 lib/dry/logic/operations/each.rb
dry-logic-1.0.4 lib/dry/logic/operations/each.rb
dry-logic-1.0.3 lib/dry/logic/operations/each.rb
dry-logic-1.0.2 lib/dry/logic/operations/each.rb