Module: Mona::DictResult
- Includes:
- Result
- Included in:
- Err, OK
- Defined in:
- lib/mona/dict_result.rb,
lib/mona/dict_result/ok.rb,
lib/mona/dict_result/err.rb,
lib/mona/dict_result/sequence.rb
Overview
Represents a dictionary of results, it is successful if all results are successful, and a failure if one is a failure. A DictResult can only contain one failure.
Defined Under Namespace
Classes: Err, OK, Sequence
Constant Summary
collapse
- EMPTY =
DictResult::OK.new({}).freeze
Constants included
from Result
Result::VERSION
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Result
#==, #and_tap, #and_then, #deconstruct, #deconstruct_keys, #either, #err, #err?, #ok, #ok?, #or_else, #value_or
Class Method Details
.[](initial = {}, &block) ⇒ Object
factory method that returns DictResult::OK or DictResult::Err
14
15
16
17
18
19
|
# File 'lib/mona/dict_result.rb', line 14
def self.[](initial = {}, &block)
result = EMPTY
initial.each { |k, v| result = result.set(k, v) }
result = result.sequence(&block) if block
result
end
|
Instance Method Details
#get(key) ⇒ Object
23
|
# File 'lib/mona/dict_result.rb', line 23
def get(key) = to_h.fetch(key)
|
#key?(key) ⇒ Boolean
21
|
# File 'lib/mona/dict_result.rb', line 21
def key?(key) = to_h.key?(key)
|
#sequence ⇒ Object
29
|
# File 'lib/mona/dict_result.rb', line 29
def sequence(&) = Sequence.new(self).call(&)
|
#set(_key, _val) ⇒ Object
25
|
# File 'lib/mona/dict_result.rb', line 25
def set(_key, _val) = raise(NotImplementedError, "implement #to_h")
|
#to_h ⇒ Object
27
|
# File 'lib/mona/dict_result.rb', line 27
def to_h = raise(NotImplementedError, "implement #to_h")
|