class ReSorcery::Result::Ok

Public Class Methods

new(value) click to toggle source
# File lib/re_sorcery/result/ok.rb, line 6
def initialize(value)
  @value = value
end

Public Instance Methods

==(other) click to toggle source
# File lib/re_sorcery/result/ok.rb, line 37
def ==(other)
  other.class == Ok && other.instance_eval { @value } == @value
end
and_then(&block) click to toggle source
# File lib/re_sorcery/result/ok.rb, line 10
def and_then(&block)
  ArgCheck['block', block.call(@value), Ok, Err]
end
as_json(*) click to toggle source
# File lib/re_sorcery/result/ok.rb, line 41
def as_json(*)
  {
    kind: :ok,
    value: @value,
  }
end
assign(name, &block) click to toggle source
# File lib/re_sorcery/result/ok.rb, line 26
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:) click to toggle source
# File lib/re_sorcery/result/ok.rb, line 33
def cata(ok:, err:)
  ok.call(@value)
end
map(&block) click to toggle source
# File lib/re_sorcery/result/ok.rb, line 14
def map(&block)
  Ok.new(block.call(@value))
end
map_error() click to toggle source
# File lib/re_sorcery/result/ok.rb, line 18
def map_error
  self
end
or_else() click to toggle source
# File lib/re_sorcery/result/ok.rb, line 22
def or_else
  self
end