<commit_before>require 'dry/types/builder'
require 'dry/types/result'
require 'dry/types/options'

module Dry
  module Types
    class Definition
      include Dry::Equalizer(:primitive, :options)
      include Options
      include Builder

      attr_reader :options

      attr_reader :primitive

      def self.[](primitive)
        if primitive == ::Array
          Types::Array
        elsif primitive == ::Hash
          Types::Hash
        else
          self
        end
      end

      def initialize(primitive, options = {})
        super
        @primitive = primitive
        freeze
      end

      def name
        primitive.name
      end

      def call(input)
        input
      end
      alias_method :[], :call

      def try(input, &block)
        output = call(input)

        if valid?(output)
          success(output)
        else
          failure = failure(output, "#{output.inspect} must be an instance of #{primitive}")
          block ? yield(failure) : failure
        end
      end

      def success(*args)
        result(Result::Success, *args)
      end

      def failure(*args)
        result(Result::Failure, *args)
      end

      def result(klass, *args)
        klass.new(*args)
      end

      def primitive?(value)
        value.is_a?(primitive)
      end
      alias_method :valid?, :primitive?
    end
  end
end

require 'dry/types/array'
require 'dry/types/hash'<commit_msg>No need to use #call in Definition#try<commit_after>require 'dry/types/builder'
require 'dry/types/result'
require 'dry/types/options'

module Dry
  module Types
    class Definition
      include Dry::Equalizer(:primitive, :options)
      include Options
      include Builder

      attr_reader :options

      attr_reader :primitive

      def self.[](primitive)
        if primitive == ::Array
          Types::Array
        elsif primitive == ::Hash
          Types::Hash
        else
          self
        end
      end

      def initialize(primitive, options = {})
        super
        @primitive = primitive
        freeze
      end

      def name
        primitive.name
      end

      def call(input)
        input
      end
      alias_method :[], :call

      def try(input, &block)
        if valid?(input)
          success(input)
        else
          failure = failure(input, "#{input.inspect} must be an instance of #{primitive}")
          block ? yield(failure) : failure
        end
      end

      def success(*args)
        result(Result::Success, *args)
      end

      def failure(*args)
        result(Result::Failure, *args)
      end

      def result(klass, *args)
        klass.new(*args)
      end

      def primitive?(value)
        value.is_a?(primitive)
      end
      alias_method :valid?, :primitive?
    end
  end
end

require 'dry/types/array'
require 'dry/types/hash'
{'fraction_non_alphanumeric': 0.0926382529059528, 'fraction_numerical': 0.0, 'mean_word_length': 1.8371628371628372, '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': '6858281', 'n_tokens_mistral': 811, 'n_tokens_neox': 795, 'n_words': 217}