Class: Dry::Monads::Result::Fixed

Inherits:
Module
  • Object
show all
Defined in:
lib/dry/monads/result/fixed.rb

Overview

See Also:

  • Monads#Result

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(error, **_options) ⇒ Fixed

Returns a new instance of Fixed.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/dry/monads/result/fixed.rb', line 15

def initialize(error, **_options)
  super()

  @mod = ::Module.new do
    define_method(:Failure) do |value|
      if error === value
        Failure.new(value, RightBiased::Left.trace_caller)
      else
        # per https://github.com/dry-rb/dry-monads/pull/142
        raise InvalidFailureTypeError.new(value)
      end
    end

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

Class Method Details

.[](error, **options) ⇒ Object



11
12
13
# File 'lib/dry/monads/result/fixed.rb', line 11

def self.[](error, **options)
  new(error, **options)
end