Sha256: 07b500b3f5b4cb9b2457696cf1ab90e39dbe1af25bd53956dd70b21c236a3281

Contents?: true

Size: 673 Bytes

Versions: 1

Compression:

Stored size: 673 Bytes

Contents

module Dry::Monads
  class Result
    # @see Monads#Result
    # @api private
    class Fixed < Module
      def self.[](error, **options)
        new(error, **options)
      end

      def initialize(error, **options)
        @mod = Module.new do
          define_method(:Failure) do |value|
            if error === value
              Failure.new(value)
            else
              raise InvalidFailureTypeError.new(value)
            end
          end

          def Success(value)
            Success.new(value)
          end
        end
      end

      # @api private
      def included(base)
        super

        base.include(@mod)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
dry-monads-0.4.0 lib/dry/monads/result/fixed.rb