Class: Jade::Ok
- Inherits:
-
Data
- Object
- Data
- Jade::Ok
- Defined in:
- lib/jade/result.rb
Instance Method Summary collapse
- #and_tap ⇒ Object
- #and_then {|ok| ... } ⇒ Object
- #and_then_combine ⇒ Object
- #error? ⇒ Boolean
-
#initialize(ok: nil) ⇒ Ok
constructor
A new instance of Ok.
- #map ⇒ Object (also: #map_both)
- #map2(result) ⇒ Object
- #map_error ⇒ Object
- #ok? ⇒ Boolean
- #on_err(_error_type = nil) ⇒ Object
- #with_default(_default) ⇒ Object
Constructor Details
#initialize(ok: nil) ⇒ Ok
Returns a new instance of Ok.
5 6 7 |
# File 'lib/jade/result.rb', line 5 def initialize(ok: nil) super end |
Instance Method Details
#and_tap ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/jade/result.rb', line 18 def and_tap result = yield(ok) case result in Ok then self in Err then result end end |
#and_then {|ok| ... } ⇒ Object
14 15 16 |
# File 'lib/jade/result.rb', line 14 def and_then yield(ok) end |
#and_then_combine ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/jade/result.rb', line 37 def and_then_combine result = yield(ok) case result in Ok(ok2) then Ok.new([*ok, ok2]) in Err(_) then result end end |
#error? ⇒ Boolean
57 58 59 |
# File 'lib/jade/result.rb', line 57 def error? false end |
#map ⇒ Object Also known as: map_both
9 10 11 |
# File 'lib/jade/result.rb', line 9 def map Ok.new(yield(ok)) end |
#map2(result) ⇒ Object
30 31 32 33 34 35 |
# File 'lib/jade/result.rb', line 30 def map2(result) case result in Ok(ok2) then Ok.new(yield(ok, ok2)) in Err(_) then result end end |
#map_error ⇒ Object
26 27 28 |
# File 'lib/jade/result.rb', line 26 def map_error self end |
#ok? ⇒ Boolean
53 54 55 |
# File 'lib/jade/result.rb', line 53 def ok? true end |
#on_err(_error_type = nil) ⇒ Object
45 46 47 |
# File 'lib/jade/result.rb', line 45 def on_err(_error_type = nil) self end |
#with_default(_default) ⇒ Object
49 50 51 |
# File 'lib/jade/result.rb', line 49 def with_default(_default) ok end |