class Kind::Result::Success

Constants

DEFAULT_TYPE

Public Instance Methods

>>(callable = UNDEFINED, &fn)
Alias for: map!
and_then(callable = UNDEFINED, &fn)
Alias for: map
and_then!(callable = UNDEFINED, &fn)
Alias for: map!
inspect() click to toggle source
# File lib/kind/result/success.rb, line 35
def inspect
  '#<%s type=%p value=%p>' % ['Kind::Success', type, value]
end
map(callable = UNDEFINED, &fn) click to toggle source
# File lib/kind/result/success.rb, line 15
def map(callable = UNDEFINED, &fn)
  _resolve_map(callable, fn)
rescue Kind::Monad::Error => e
  raise e
rescue StandardError => e
  Result::Failure[:exception, e]
end
Also aliased as: then, and_then
map!(callable = UNDEFINED, &fn) click to toggle source
# File lib/kind/result/success.rb, line 26
def map!(callable = UNDEFINED, &fn)
  _resolve_map(callable, fn)
end
Also aliased as: |, >>, then!, and_then!
success?() click to toggle source
# File lib/kind/result/success.rb, line 7
def success?
  true
end
then(callable = UNDEFINED, &fn)
Alias for: map
then!(callable = UNDEFINED, &fn)
Alias for: map!
value_or(_default = UNDEFINED, &block) click to toggle source
# File lib/kind/result/success.rb, line 11
def value_or(_default = UNDEFINED, &block)
  @value
end
|(callable = UNDEFINED, &fn)
Alias for: map!

Private Instance Methods

_map(fn) click to toggle source
# File lib/kind/result/success.rb, line 45
def _map(fn)
  monad = fn.call(@value)

  return monad if Result::Monad === monad

  raise Kind::Monad::Error.new('Kind::Success | Kind::Failure', monad)
end
_resolve_map(callable, fn) click to toggle source
# File lib/kind/result/success.rb, line 41
def _resolve_map(callable, fn)
  callable.respond_to?(:call) ? _map(callable) : _map(fn)
end