<commit_before>module Dry
  module Validation
    class Result
      include Dry::Equalizer(:output, :messages)

      attr_reader :output
      attr_reader :errors
      attr_reader :error_compiler
      attr_reader :hint_compiler

      EMPTY_MESSAGES = {}.freeze

      def initialize(output, errors, error_compiler, hint_compiler)
        @output = output
        @errors = errors
        @error_compiler = error_compiler
        @hint_compiler = hint_compiler
      end

      def success?
        errors.empty?
      end

      def failure?
        !success?
      end

      def messages(options = {})
        @messages ||=
          begin
            return EMPTY_MESSAGES if success?

            hints = hint_compiler.with(options).call
            comp = error_compiler.with(options.merge(hints: hints))

            comp.(errors.map { |error| error.to_ast })
          end
      end

      def to_ast
        [:set, error_ast]
      end

      private

      def error_ast
        errors.map { |error| error.to_ast }
      end
    end
  end<commit_msg>Fix duplication in Validation::Result#messages<commit_after>module Dry
  module Validation
    class Result
      include Dry::Equalizer(:output, :messages)

      attr_reader :output
      attr_reader :errors
      attr_reader :error_compiler
      attr_reader :hint_compiler

      EMPTY_MESSAGES = {}.freeze

      def initialize(output, errors, error_compiler, hint_compiler)
        @output = output
        @errors = errors
        @error_compiler = error_compiler
        @hint_compiler = hint_compiler
      end

      def success?
        errors.empty?
      end

      def failure?
        !success?
      end

      def messages(options = {})
        @messages ||=
          begin
            return EMPTY_MESSAGES if success?

            hints = hint_compiler.with(options).call
            comp = error_compiler.with(options.merge(hints: hints))

            comp.(error_ast)
          end
      end

      def to_ast
        [:set, error_ast]
      end

      private

      def error_ast
        errors.map { |error| error.to_ast }
      end
    end
  end
{'fraction_non_alphanumeric': 0.07259953161592506, 'fraction_numerical': 0.0, 'mean_word_length': 1.8632707774798927, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6859835', 'n_tokens_mistral': 615, 'n_tokens_neox': 580, 'n_words': 146}