Class: Dry::Monads::Validated::Valid 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.

Valid result

Instance Method Summary collapse

Methods inherited from Dry::Monads::Validated

#bind, pure, #to_monad

Constructor Details

#initialize(value) ⇒ Valid

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



59
60
61
62
63
# File 'lib/dry/monads/validated.rb', line 59

def initialize(value)
  super()

  @value = value
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)


133
134
135
# File 'lib/dry/monads/validated.rb', line 133

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

#alt_map(_ = nil) ⇒ Validated::Valid

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 values and returns self, see Invalid#alt_map

Returns:



110
111
112
# File 'lib/dry/monads/validated.rb', line 110

def alt_map(_ = nil)
  self
end

#apply(val) ⇒ Validated::Valid, Validated::Invalid #applyValidated::Valid, 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.

Applies another Valid to the stored function

Overloads:



88
89
90
# File 'lib/dry/monads/validated.rb', line 88

def apply(val = Undefined, &block)
  Undefined.default(val, &block).fmap(Curry.(value!))
end

#fmap(proc) ⇒ Validated::Valid #fmapValidated::Valid

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 Valid

Overloads:



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

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


122
123
124
125
126
127
128
# File 'lib/dry/monads/validated.rb', line 122

def inspect
  if Unit.equal?(@value)
    "Valid()"
  else
    "Valid(#{@value.inspect})"
  end
end

#or(_ = nil) ⇒ Validated::Valid

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 arguments, returns self

Returns:



117
118
119
# File 'lib/dry/monads/validated.rb', line 117

def or(_ = nil)
  self
end

#to_maybeMaybe::Some

Converts to Maybe::Some

Returns:



436
437
438
# File 'lib/dry/monads/maybe.rb', line 436

def to_maybe
  Maybe.pure(value!)
end

#to_resultResult::Success

Converts to Result::Success

Returns:



463
464
465
# File 'lib/dry/monads/result.rb', line 463

def to_result
  Result.pure(value!)
end

#value!Object

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.

Extracts the value

Returns:

  • (Object)


68
69
70
# File 'lib/dry/monads/validated.rb', line 68

def value!
  @value
end