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.



154
155
156
157
# File 'lib/dry/monads/validated.rb', line 154

def initialize(error, trace = RightBiased::Left.trace_caller)
  @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

Returns:

  • (Object)


144
145
146
# File 'lib/dry/monads/validated.rb', line 144

def error
  @error
end

#traceString (readonly)

Line where the value was constructed

Returns:

  • (String)


150
151
152
# File 'lib/dry/monads/validated.rb', line 150

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.

Parameters:

  • other (Object)

Returns:

  • (Boolean)


220
221
222
# File 'lib/dry/monads/validated.rb', line 220

def ===(other)
  self.class == other.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

Overloads:



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

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:



169
170
171
172
173
174
# File 'lib/dry/monads/validated.rb', line 169

def apply(val = Undefined)
  Undefined.
    default(val) { yield }.
    alt_map { |v| @error + v }.
    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

Returns:



194
195
196
# File 'lib/dry/monads/validated.rb', line 194

def fmap(_ = nil)
  self
end

#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.

Returns:

  • (String)


213
214
215
# File 'lib/dry/monads/validated.rb', line 213

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

#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

Overloads:

  • #or(proc) ⇒ Object

    Parameters:

    • proc (#call)

    Returns:

    • (Object)
  • #orObject

    Parameters:

    • block (Proc)

    Returns:

    • (Object)


208
209
210
# File 'lib/dry/monads/validated.rb', line 208

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

#to_maybeMaybe::None

Converts to Maybe::None

Returns:



383
384
385
# File 'lib/dry/monads/maybe.rb', line 383

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

#to_resultResult::Failure

Concerts to Result::Failure

Returns:



453
454
455
# File 'lib/dry/monads/result.rb', line 453

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