Class: Dry::Monads::Validated::Invalid
- Inherits:
-
Dry::Monads::Validated
- Object
- Dry::Monads::Validated
- Dry::Monads::Validated::Invalid
- Defined in:
- lib/dry/monads/validated.rb,
lib/dry/monads/maybe.rb,
lib/dry/monads/result.rb
Overview
Invalid result
Instance Attribute Summary collapse
-
#error ⇒ Object
readonly
The value stored inside.
-
#trace ⇒ String
readonly
Line where the value was constructed.
Instance Method Summary collapse
- #===(other) ⇒ Boolean
-
#alt_map(proc = Undefined, &block) ⇒ Object
Lifts a block/proc over Invalid.
-
#apply(val = Undefined) ⇒ Object
Collects errors (ignores valid results).
-
#fmap(_ = nil) ⇒ Validated::Invalid
Ignores the passed argument and returns self.
-
#initialize(error, trace = RightBiased::Left.trace_caller) ⇒ Invalid
constructor
A new instance of Invalid.
- #inspect ⇒ String (also: #to_s)
-
#or(proc = Undefined, &block) ⇒ Object
Yields the given callable and returns the result.
-
#to_maybe ⇒ Maybe::None
Converts to Maybe::None.
-
#to_result ⇒ Result::Failure
Concerts to Result::Failure.
Methods inherited from Dry::Monads::Validated
Constructor Details
#initialize(error, trace = RightBiased::Left.trace_caller) ⇒ Invalid
Returns a new instance of Invalid.
150 151 152 153 |
# File 'lib/dry/monads/validated.rb', line 150 def initialize(error, trace = RightBiased::Left.trace_caller) @error = error @trace = trace end |
Instance Attribute Details
#error ⇒ Object (readonly)
The value stored inside
140 141 142 |
# File 'lib/dry/monads/validated.rb', line 140 def error @error end |
#trace ⇒ String (readonly)
Line where the value was constructed
146 147 148 |
# File 'lib/dry/monads/validated.rb', line 146 def trace @trace end |
Instance Method Details
#===(other) ⇒ Boolean
216 217 218 |
# File 'lib/dry/monads/validated.rb', line 216 def ===(other) self.class == other.class && error === other.error end |
#alt_map(proc) ⇒ Validated::Invalid #alt_map ⇒ Validated::Invalid
Lifts a block/proc over Invalid
182 183 184 185 |
# File 'lib/dry/monads/validated.rb', line 182 def alt_map(proc = Undefined, &block) f = Undefined.default(proc, block) self.class.new(f.(error), RightBiased::Left.trace_caller) end |
#apply(val) ⇒ Validated::Invalid #apply ⇒ Validated::Invalid
Collects errors (ignores valid results)
165 166 167 168 169 170 |
# File 'lib/dry/monads/validated.rb', line 165 def apply(val = Undefined) Undefined. default(val) { yield }. alt_map { |v| @error + v }. fmap { return self } end |
#fmap(_ = nil) ⇒ Validated::Invalid
Ignores the passed argument and returns self
190 191 192 |
# File 'lib/dry/monads/validated.rb', line 190 def fmap(_ = nil) self end |
#inspect ⇒ String Also known as: to_s
209 210 211 |
# File 'lib/dry/monads/validated.rb', line 209 def inspect "Invalid(#{ @error.inspect })" end |
#or(proc) ⇒ Object #or ⇒ Object
Yields the given callable and returns the result
204 205 206 |
# File 'lib/dry/monads/validated.rb', line 204 def or(proc = Undefined, &block) Undefined.default(proc, block).call end |
#to_maybe ⇒ Maybe::None
Converts to Maybe::None
294 295 296 |
# File 'lib/dry/monads/maybe.rb', line 294 def to_maybe Maybe::None.new(RightBiased::Left.trace_caller) end |
#to_result ⇒ Result::Failure
Concerts to Result::Failure
363 364 365 |
# File 'lib/dry/monads/result.rb', line 363 def to_result Result::Failure.new(error, RightBiased::Left.trace_caller) end |