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.


10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/dry/monads/result/fixed.rb', line 10

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

Class Method Details

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


6
7
8
# File 'lib/dry/monads/result/fixed.rb', line 6

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

Instance Method Details

#included(base) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


28
29
30
31
32
# File 'lib/dry/monads/result/fixed.rb', line 28

def included(base)
  super

  base.include(@mod)
end