Sha256: 0a375ae4719ac8e74d6773dd2ce97fc98096ee4d198c10329e453d2d9ae8b649

Contents?: true

Size: 773 Bytes

Versions: 2

Compression:

Stored size: 773 Bytes

Contents

module Dry::Monads
  class Result
    # @see Monads#Result
    # @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, RightBiased::Left.trace_caller)
            else
              raise InvalidFailureTypeError.new(value)
            end
          end

          def Success(value = Undefined, &block)
            v = Undefined.default(value, block || Unit)
            Success.new(v)
          end
        end
      end

      # @api private
      def included(base)
        super

        base.include(@mod)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
dry-monads-1.2.0 lib/dry/monads/result/fixed.rb
dry-monads-1.1.0 lib/dry/monads/result/fixed.rb