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/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

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



16
17
18
# File 'lib/dry/monads/result.rb', line 16

def failure
  @failure
end

#successObject (readonly)

Returns Successful result.

Returns:

  • (Object)

    Successful result



13
14
15
# File 'lib/dry/monads/result.rb', line 13

def success
  @success
end

Class Method Details

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

Wraps the given value with Success.

Overloads:



29
30
31
# File 'lib/dry/monads/result.rb', line 29

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)


52
53
54
# File 'lib/dry/monads/result.rb', line 52

def monad
  Result
end

#to_monadResult::Success, Result::Failure

Returns self.



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

def to_monad
  self
end

#to_resultResult::Success, Result::Failure

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



37
38
39
# File 'lib/dry/monads/result.rb', line 37

def to_result
  self
end