class Dry::Monads::Result

Represents an operation which either succeeded or failed.

@api public

Attributes

failure[R]

@return [Object] Error

success[R]

@return [Object] Successful result

Public Class Methods

pure(value = Undefined, &block) click to toggle source

Wraps the given value with Success.

@overload pure(value)

@param value [Object]
@return [Result::Success]

@overload pure(&block)

@param block [Proc] a block to be wrapped with Success
@return [Result::Success]
# File lib/dry/monads/result.rb, line 29
def pure(value = Undefined, &block)
  Success.new(Undefined.default(value, block))
end

Public Instance Methods

monad() click to toggle source

Returns the Result monad. This is how we’re doing polymorphism in Ruby 😕

@return [Monad]

# File lib/dry/monads/result.rb, line 52
def monad
  Result
end
to_monad() click to toggle source

Returns self.

@return [Result::Success, Result::Failure]

# File lib/dry/monads/result.rb, line 44
def to_monad
  self
end
to_result() click to toggle source

Returns self, added to keep the interface compatible with other monads.

@return [Result::Success, Result::Failure]

# File lib/dry/monads/result.rb, line 37
def to_result
  self
end