Class: Dry::Monads::Validated::Invalid Private

Inherits:
Dry::Monads::Validated show all
Defined in:
lib/dry/monads/validated.rb,
lib/dry/monads/maybe.rb,
lib/dry/monads/result.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Invalid result

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Dry::Monads::Validated

#bind, pure, #to_monad

Constructor Details

#initialize(error, trace = RightBiased::Left.trace_caller) ⇒ Invalid

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Invalid.



146
147
148
149
150
151
# File 'lib/dry/monads/validated.rb', line 146

def initialize(error, trace = RightBiased::Left.trace_caller)
  super()

  @error = error
  @trace = trace
end

Instance Attribute Details

#errorObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The value stored inside



136
137
138
# File 'lib/dry/monads/validated.rb', line 136

def error
  @error
end

#traceString (readonly)

Line where the value was constructed



142
143
144
# File 'lib/dry/monads/validated.rb', line 142

def trace
  @trace
end

Instance Method Details

#===(other) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



210
211
212
# File 'lib/dry/monads/validated.rb', line 210

def ===(other)
  other.instance_of?(self.class) && error === other.error
end

#alt_map(proc) ⇒ Validated::Invalid #alt_mapValidated::Invalid

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Lifts a block/proc over Invalid



180
181
182
183
# 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

#apply(val) ⇒ Validated::Invalid #applyValidated::Invalid

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Collects errors (ignores valid results)

Overloads:



163
164
165
166
167
168
# 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

#fmap(_ = nil) ⇒ Validated::Invalid

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Ignores the passed argument and returns self



188
# File 'lib/dry/monads/validated.rb', line 188

def fmap(_ = nil, &) = self

#inspectString Also known as: to_s

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



205
# File 'lib/dry/monads/validated.rb', line 205

def inspect = "Invalid(#{@error.inspect})"

#or(proc) ⇒ Object #orObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Yields the given callable and returns the result



200
201
202
# File 'lib/dry/monads/validated.rb', line 200

def or(proc = Undefined, &block)
  Undefined.default(proc, block).call
end

#to_maybeMaybe::None

Converts to Maybe::None



408
# File 'lib/dry/monads/maybe.rb', line 408

def to_maybe = Maybe::None.new(RightBiased::Left.trace_caller)

#to_resultResult::Failure

Converts to Result::Failure



432
433
434
# File 'lib/dry/monads/result.rb', line 432

def to_result
  Result::Failure.new(error, RightBiased::Left.trace_caller)
end