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