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.



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

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

Returns:



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

def apply(val = Undefined)
  Undefined.default(val) { yield }.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:



374
375
376
# File 'lib/dry/monads/maybe.rb', line 374

def to_maybe
  Maybe.pure(value!)
end

#to_resultResult::Success

Converts to Result::Success

Returns:



444
445
446
# File 'lib/dry/monads/result.rb', line 444

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)


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

def value!
  @value
end