Class: Dry::Monads::Validated::Valid
- Inherits:
-
Dry::Monads::Validated
- Object
- Dry::Monads::Validated
- Dry::Monads::Validated::Valid
- Defined in:
- lib/dry/monads/validated.rb,
lib/dry/monads/maybe.rb,
lib/dry/monads/result.rb
Overview
Valid result
Instance Method Summary collapse
- #===(other) ⇒ Boolean
-
#alt_map(_ = nil) ⇒ Validated::Valid
Ignores values and returns self, see Invalid#alt_map.
-
#apply(val = Undefined) ⇒ Validated::Valid
Applies another Valid to the stored function.
-
#fmap(proc = Undefined, &block) ⇒ Object
Lifts a block/proc over Valid.
-
#initialize(value) ⇒ Valid
constructor
A new instance of Valid.
- #inspect ⇒ String (also: #to_s)
-
#or(_ = nil) ⇒ Validated::Valid
Ignores arguments, returns self.
-
#to_maybe ⇒ Maybe::Some
Converts to Maybe::Some.
-
#to_result ⇒ Result::Success
Converts to Result::Success.
-
#value! ⇒ Object
Extracts the value.
Methods inherited from Dry::Monads::Validated
Constructor Details
#initialize(value) ⇒ Valid
Returns a new instance of Valid.
60 61 62 |
# File 'lib/dry/monads/validated.rb', line 60 def initialize(value) @value = value end |
Instance Method Details
#===(other) ⇒ Boolean
129 130 131 |
# File 'lib/dry/monads/validated.rb', line 129 def ===(other) self.class == other.class && value! === other.value! end |
#alt_map(_ = nil) ⇒ Validated::Valid
Ignores values and returns self, see Invalid#alt_map
110 111 112 |
# File 'lib/dry/monads/validated.rb', line 110 def alt_map(_ = nil) self end |
#apply(val) ⇒ Validated::Valid, Validated::Invalid #apply ⇒ Validated::Valid, Validated::Invalid
Applies another Valid to the stored function
88 89 90 |
# File 'lib/dry/monads/validated.rb', line 88 def apply(val = Undefined) Undefined.default(val) { yield }.fmap(Curry.(value!)) end |
#fmap(proc) ⇒ Validated::Valid #fmap ⇒ Validated::Valid
Lifts a block/proc over Valid
102 103 104 105 |
# File 'lib/dry/monads/validated.rb', line 102 def fmap(proc = Undefined, &block) f = Undefined.default(proc, block) self.class.new(f.(value!)) end |
#inspect ⇒ String Also known as: to_s
122 123 124 |
# File 'lib/dry/monads/validated.rb', line 122 def inspect "Valid(#{ value!.inspect })" end |
#or(_ = nil) ⇒ Validated::Valid
Ignores arguments, returns self
117 118 119 |
# File 'lib/dry/monads/validated.rb', line 117 def or(_ = nil) self end |
#to_maybe ⇒ Maybe::Some
Converts to Maybe::Some
285 286 287 |
# File 'lib/dry/monads/maybe.rb', line 285 def to_maybe Maybe.pure(value!) end |
#to_result ⇒ Result::Success
Converts to Result::Success
354 355 356 |
# File 'lib/dry/monads/result.rb', line 354 def to_result Result.pure(value!) end |
#value! ⇒ Object
Extracts the value
67 68 69 |
# File 'lib/dry/monads/validated.rb', line 67 def value! @value end |