Class: Dry::Monads::Result

Inherits:
Object
  • Object
show all
Includes:
Transformer
Defined in:
lib/dry/monads/result.rb,
lib/dry/monads/maybe.rb,
lib/dry/monads/either.rb,
lib/dry/monads/validated.rb,
lib/dry/monads/result/fixed.rb

Overview

Represents an operation which either succeeded or failed.

Direct Known Subclasses

Failure, Success

Defined Under Namespace

Modules: Mixin Classes: Failure, Fixed, Success

Constant Summary collapse

Right =
Success
Left =
Failure

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Transformer

#fmap2, #fmap3

Instance Attribute Details

#failureObject (readonly)

Returns Error.

Returns:

  • (Object)

    Error


22
23
24
# File 'lib/dry/monads/result.rb', line 22

def failure
  @failure
end

#successObject (readonly)

Returns Successful result.

Returns:

  • (Object)

    Successful result


19
20
21
# File 'lib/dry/monads/result.rb', line 19

def success
  @success
end

Class Method Details

.pure(value) ⇒ Result::Success .pure(&block) ⇒ Result::Success

Wraps the given value with Success.

Overloads:


35
36
37
# File 'lib/dry/monads/result.rb', line 35

def pure(value = Undefined, &block)
  Success.new(Undefined.default(value, block))
end

Instance Method Details

#monadMonad

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

Returns:

  • (Monad)

58
59
60
# File 'lib/dry/monads/result.rb', line 58

def monad
  Result
end

#to_monadResult::Success, Result::Failure

Returns self.


50
51
52
# File 'lib/dry/monads/result.rb', line 50

def to_monad
  self
end

#to_resultResult::Success, Result::Failure

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


43
44
45
# File 'lib/dry/monads/result.rb', line 43

def to_result
  self
end