Class: ReSorcery::Result::Ok
- Inherits:
-
Object
- Object
- ReSorcery::Result::Ok
- Defined in:
- lib/re_sorcery/result/ok.rb
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #and_then(&block) ⇒ Object
- #as_json ⇒ Object
- #assign(name, &block) ⇒ Object
- #cata(ok:, err:) ⇒ Object
-
#initialize(value) ⇒ Ok
constructor
A new instance of Ok.
- #map(&block) ⇒ Object
- #map_error ⇒ Object
- #or_else ⇒ Object
Constructor Details
#initialize(value) ⇒ Ok
Returns a new instance of Ok.
14 15 16 |
# File 'lib/re_sorcery/result/ok.rb', line 14 def initialize(value) @value = value end |
Class Method Details
Instance Method Details
#==(other) ⇒ Object
45 46 47 |
# File 'lib/re_sorcery/result/ok.rb', line 45 def ==(other) other.class == Ok && other.instance_eval { @value } == @value end |
#and_then(&block) ⇒ Object
18 19 20 |
# File 'lib/re_sorcery/result/ok.rb', line 18 def and_then(&block) ArgCheck['block', block.call(@value), Ok, Err] end |
#as_json ⇒ Object
49 50 51 52 53 54 |
# File 'lib/re_sorcery/result/ok.rb', line 49 def as_json(*) { kind: :ok, value: @value, } end |
#assign(name, &block) ⇒ Object
34 35 36 37 38 39 |
# File 'lib/re_sorcery/result/ok.rb', line 34 def assign(name, &block) raise Error::NonHashAssignError, @value unless @value.is_a?(Hash) ArgCheck['block', block.call(@value), Ok, Err] .map { |k| @value.merge(name => k) } end |
#cata(ok:, err:) ⇒ Object
41 42 43 |
# File 'lib/re_sorcery/result/ok.rb', line 41 def cata(ok:, err:) ok.call(@value) end |
#map(&block) ⇒ Object
22 23 24 |
# File 'lib/re_sorcery/result/ok.rb', line 22 def map(&block) Ok.new(block.call(@value)) end |
#map_error ⇒ Object
26 27 28 |
# File 'lib/re_sorcery/result/ok.rb', line 26 def map_error self end |
#or_else ⇒ Object
30 31 32 |
# File 'lib/re_sorcery/result/ok.rb', line 30 def or_else self end |