Class: Mona::DictResult::Sequence
- Inherits:
-
Object
- Object
- Mona::DictResult::Sequence
- Defined in:
- lib/mona/dict_result/sequence.rb
Overview
Sequence.call { … } allows monadic ‘do’ notation for DictResult, where #set-ing the first failure skips the remainder of the block and returns the DictResult
Class Method Summary collapse
Instance Method Summary collapse
- #call ⇒ Object
- #get(key) ⇒ Object
-
#initialize(result = DictResult::EMPTY) ⇒ Sequence
constructor
A new instance of Sequence.
- #key?(key) ⇒ Boolean
- #set(key, value) ⇒ Object
Constructor Details
#initialize(result = DictResult::EMPTY) ⇒ Sequence
10 11 12 13 |
# File 'lib/mona/dict_result/sequence.rb', line 10 def initialize(result = DictResult::EMPTY) @result = result @throw = Object.new end |
Class Method Details
.call(result = DictResult::EMPTY) ⇒ Object
8 |
# File 'lib/mona/dict_result/sequence.rb', line 8 def self.call(result = DictResult::EMPTY, &) = new(result).call(&) |
Instance Method Details
#call ⇒ Object
15 16 17 18 19 20 |
# File 'lib/mona/dict_result/sequence.rb', line 15 def call catch(@throw) do yield self @result end end |
#get(key) ⇒ Object
28 |
# File 'lib/mona/dict_result/sequence.rb', line 28 def get(key) = @result.get(key) |
#key?(key) ⇒ Boolean
30 |
# File 'lib/mona/dict_result/sequence.rb', line 30 def key?(key) = @result.key?(key) |
#set(key, value) ⇒ Object
22 23 24 25 26 |
# File 'lib/mona/dict_result/sequence.rb', line 22 def set(key, value) @result = @result.set(key, value) ensure throw @throw, @result if @result.err? end |