Class: Mona::Result::Dict::OK

Inherits:
OK
  • Object
show all
Includes:
ReadInterface
Defined in:
lib/mona/result/dict.rb

Overview

OK dict result

Since:

  • 0.1.0

Instance Attribute Summary

Attributes inherited from OK

#value

Instance Method Summary collapse

Methods included from ReadInterface

#[], #fetch, #key?

Methods inherited from OK

#and_tap, #and_then, #deconstruct, #deconstruct_keys, #either, #err, #err?, #initialize, #ok, #ok?, #or_else, #to_result, #to_s, #value_or

Constructor Details

This class inherits a constructor from Mona::Result::OK

Instance Method Details

#sequenceObject

Since:

  • 0.1.0



38
# File 'lib/mona/result/dict.rb', line 38

def sequence(&) = Sequence.new(self).call(&)

#set(key, to_result) ⇒ Object

Since:

  • 0.1.0



29
30
31
32
33
34
35
36
# File 'lib/mona/result/dict.rb', line 29

def set(key, to_result)
  key, failure_key = key if key.is_a?(Array)
  failure_key ||= key

  Result[to_result].either \
    ->(value)                { OK.new to_h.merge(key => value) },
    ->(failure, reason, **m) { Err.new to_h.merge(failure_key => failure), reason, **m, key: failure_key }
end

#to_hObject

Since:

  • 0.1.0



40
# File 'lib/mona/result/dict.rb', line 40

def to_h = @value