Class: Dry::Monads::Validated::Valid

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

Overview

Valid result

Instance Method Summary collapse

Methods inherited from Dry::Monads::Validated

#bind, pure, #to_monad

Constructor Details

#initialize(value) ⇒ Valid

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

Parameters:

  • other (Object)

Returns:

  • (Boolean)

129
130
131
# File 'lib/dry/monads/validated.rb', line 129

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

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

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

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

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

Returns:

  • (String)

122
123
124
# File 'lib/dry/monads/validated.rb', line 122

def inspect
  "Valid(#{ value!.inspect })"
end

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

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:


285
286
287
# File 'lib/dry/monads/maybe.rb', line 285

def to_maybe
  Maybe.pure(value!)
end

#to_resultResult::Success

Converts to Result::Success

Returns:


354
355
356
# File 'lib/dry/monads/result.rb', line 354

def to_result
  Result.pure(value!)
end

#value!Object

Extracts the value

Returns:

  • (Object)

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

def value!
  @value
end