class Kind::Result::Monad

Attributes

type[R]
value[R]

Public Class Methods

new(type, value) click to toggle source
# File lib/kind/result/monad.rb, line 26
def initialize(type, value)
  @type = type
  @value = value
end

Public Instance Methods

===(m) click to toggle source
# File lib/kind/result/monad.rb, line 67
def ===(m)
  return false unless Result::Abstract === m
  return false unless (self.success? && m.success?) || (self.failure? && m.failure?)

  self.type == m.type && self.value === m.value
end
>>(_ = UNDEFINED, &_fn)
Alias for: map
and_then(_ = UNDEFINED, &_fn)
Alias for: map
and_then!(_ = UNDEFINED, &_fn)
Alias for: map
map(_ = UNDEFINED, &_fn) click to toggle source
# File lib/kind/result/monad.rb, line 35
def map(_ = UNDEFINED, &_fn)
  raise NotImplementedError
end
Also aliased as: |, >>, map!, then, then!, and_then, and_then!
map!(_ = UNDEFINED, &_fn)
Alias for: map
on() { |monad| ... } click to toggle source
# File lib/kind/result/monad.rb, line 47
def on
  monad = Wrapper.new(self)

  yield(monad)

  monad.output
end
on_failure(types = Undefined, matcher = Undefined) { |value| ... } click to toggle source
# File lib/kind/result/monad.rb, line 61
def on_failure(types = Undefined, matcher = Undefined)
  yield(value) if failure? && result?(types, matcher)

  self
end
on_success(types = Undefined, matcher = Undefined) { |value| ... } click to toggle source
# File lib/kind/result/monad.rb, line 55
def on_success(types = Undefined, matcher = Undefined)
  yield(value) if success? && result?(types, matcher)

  self
end
then(_ = UNDEFINED, &_fn)
Alias for: map
then!(_ = UNDEFINED, &_fn)
Alias for: map
value_or(_method_name = UNDEFINED, &block) click to toggle source
# File lib/kind/result/monad.rb, line 31
def value_or(_method_name = UNDEFINED, &block)
  raise NotImplementedError
end
|(_ = UNDEFINED, &_fn)
Alias for: map