class Result
Public Class Methods
combine_map(list) { |item| ... }
click to toggle source
# File lib/result.rb, line 57 def self.combine_map(list) list.reduce(self.ok []) do |acc, item| break acc if acc.error? result = yield item map2(acc, result) do |acc_list, result_item| acc_list + [result_item] end end end
error(errored_thing)
click to toggle source
# File lib/result.rb, line 10 def self.error(errored_thing) new(Err.new(errored_thing)) end
map2(first_result, second_result) { |first, second| ... }
click to toggle source
# File lib/result.rb, line 69 def self.map2(first_result, second_result) first_result.then do |first| second_result.then do |second| self.ok yield first, second end end end
new(result)
click to toggle source
# File lib/result.rb, line 2 def initialize(result) @result = result end
ok(successful_thing)
click to toggle source
# File lib/result.rb, line 6 def self.ok(successful_thing) new(Ok.new(successful_thing)) end
Public Instance Methods
error?()
click to toggle source
# File lib/result.rb, line 49 def error? @result.is_a?(Err) end
map() { |extract)| ... }
click to toggle source
# File lib/result.rb, line 14 def map case @result when Ok self.class.ok(yield @result.extract) when Err self end end
map_error() { |extract)| ... }
click to toggle source
# File lib/result.rb, line 36 def map_error case @result when Err self.class.error(yield @result.extract) when Ok self end end
ok?()
click to toggle source
# File lib/result.rb, line 45 def ok? @result.is_a?(Ok) end
then() { |extract| ... }
click to toggle source
# File lib/result.rb, line 23 def then case @result when Ok yield(@result.extract).tap do |returned_result| unless returned_result.is_a?(self.class) raise InvalidReturn, 'then handler must return a Result' end end when Err self end end
when_ok(&block)
click to toggle source
# File lib/result.rb, line 53 def when_ok(&block) Case.when_ok(self, &block) end
Private Instance Methods
_result()
click to toggle source
# File lib/result.rb, line 79 def _result @result end