class Dry::Monads::Validated::Valid::Invalid
Invalid
result
Constants
- Invalid
-
@see Validated::Invalid
- Valid
-
@see
Validated::Valid
Attributes
The value stored inside
@return [Object]
Line where the value was constructed
@return [String] @api public
Private Class Methods
Source
# File lib/dry/monads/validated.rb, line 146 def initialize(error, trace = RightBiased::Left.trace_caller) super() @error = error @trace = trace end
Calls superclass method
Private Instance Methods
Source
# File lib/dry/monads/validated.rb, line 210 def ===(other) other.instance_of?(self.class) && error === other.error end
@param other [Object] @return [Boolean]
Source
# File lib/dry/monads/validated.rb, line 180 def alt_map(proc = Undefined, &block) f = Undefined.default(proc, block) self.class.new(f.(error), RightBiased::Left.trace_caller) end
Lifts a block/proc over Invalid
@overload alt_map
(proc)
@param proc [#call] @return [Validated::Invalid]
@overload alt_map
@param block [Proc] @return [Validated::Invalid]
Source
# File lib/dry/monads/validated.rb, line 163 def apply(val = Undefined, &block) Undefined .default(val, &block) .alt_map { @error + _1 } .fmap { return self } end
Collects errors (ignores valid results)
@overload apply(val)
@param val [Validated::Valid,Validated::Invalid] @return [Validated::Invalid]
@overload apply
@yieldreturn [Validated::Valid,Validated::Invalid] @return [Validated::Invalid]
Source
# File lib/dry/monads/validated.rb, line 188 def fmap(_ = nil, &) = self # Yields the given callable and returns the result # # @overload or(proc) # @param proc [#call] # @return [Object] # # @overload or # @param block [Proc] # @return [Object] # def or(proc = Undefined, &block) Undefined.default(proc, block).call end # @return [String] def inspect = "Invalid(#{@error.inspect})" alias_method :to_s, :inspect # @param other [Object] # @return [Boolean] def ===(other) other.instance_of?(self.class) && error === other.error end end # Mixin with Validated constructors # module Mixin # Successful validation result # @see Dry::Monads::Validated::Valid Valid = Valid # Unsuccessful validation result # @see Dry::Monads::Validated::Invalid Invalid = Invalid # Actual constructor methods # module Constructors # Valid constructor # # @overload Valid(value) # @param value [Object] # @return [Valdated::Valid] # # @overload Valid(&block) # @param block [Proc] # @return [Valdated::Valid] # def Valid(value = Undefined, &block) v = Undefined.default(value, block) raise ArgumentError, "No value given" if !value.nil? && v.nil? Valid.new(v) end # Invalid constructor # # @overload Invalid(value) # @param value [Object] # @return [Valdated::Invalid] # # @overload Invalid(&block) # @param block [Proc] # @return [Valdated::Invalid] # def Invalid(value = Undefined, &block) v = Undefined.default(value, block) raise ArgumentError, "No value given" if !value.nil? && v.nil? Invalid.new(v, RightBiased::Left.trace_caller) end end include Constructors end end
Ignores the passed argument and returns self
@return [Validated::Invalid]
Source
# File lib/dry/monads/validated.rb, line 205 def inspect = "Invalid(#{@error.inspect})" alias_method :to_s, :inspect # @param other [Object] # @return [Boolean] def ===(other) other.instance_of?(self.class) && error === other.error end end
@return [String]
Source
# File lib/dry/monads/validated.rb, line 200 def or(proc = Undefined, &block) Undefined.default(proc, block).call end
Yields the given callable and returns the result
@overload or(proc)
@param proc [#call] @return [Object]
@overload or
@param block [Proc] @return [Object]