Class: Mona::DictResult::OK

Inherits:
OK
  • Object
show all
Includes:
Mona::DictResult
Defined in:
lib/mona/dict_result/ok.rb

Overview

OK DictResult

Constant Summary

Constants included from Mona::DictResult

EMPTY

Constants included from Result

Result::VERSION

Instance Attribute Summary

Attributes inherited from OK

#value

Instance Method Summary collapse

Methods included from Mona::DictResult

[], #get, #key?, #sequence

Methods included from Result

#==, [], #and_tap, #and_then, #deconstruct, #deconstruct_keys, #either, #err, #err?, #ok, #ok?, #or_else, #value_or

Methods inherited from OK

[], #either, #initialize, #inspect

Constructor Details

This class inherits a constructor from Mona::OK

Instance Method Details

#set(key, val) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/mona/dict_result/ok.rb', line 9

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

  # @type var meta: Hash[Symbol, untyped]
  Result[val].either \
    ->(value) { OK.new to_h.merge(key => value) },
    ->(failure, reason, **meta) { Err.new to_h.merge(failure_key => failure), reason, **meta, key: failure_key }
end

#to_hObject



19
# File 'lib/mona/dict_result/ok.rb', line 19

def to_h = @value