class Dry::Monads::Validated::Valid

Valid result

Private Class Methods

new(value) click to toggle source
Calls superclass method
# File lib/dry/monads/validated.rb, line 59
def initialize(value)
  super()

  @value = value
end

Private Instance Methods

===(other) click to toggle source

@param other [Object] @return [Boolean]

# File lib/dry/monads/validated.rb, line 133
def ===(other)
  other.instance_of?(self.class) && value! === other.value!
end
alt_map(_ = nil) click to toggle source

Ignores values and returns self, see {Invalid#alt_map}

@return [Validated::Valid]

# File lib/dry/monads/validated.rb, line 110
def alt_map(_ = nil)
  self
end
apply(val = Undefined, &block) click to toggle source

Applies another Valid to the stored function

@overload apply(val)

@example
  Validated.pure { |x| x + 1 }.apply(Valid(2)) # => Valid(3)

@param val [Validated::Valid,Validated::Invalid]
@return [Validated::Valid,Validated::Invalid]

@overload apply

@example
  Validated.pure { |x| x + 1 }.apply { Valid(4) } # => Valid(5)

@yieldreturn [Validated::Valid,Validated::Invalid]
@return [Validated::Valid,Validated::Invalid]
# File lib/dry/monads/validated.rb, line 88
def apply(val = Undefined, &block)
  Undefined.default(val, &block).fmap(Curry.(value!))
end
fmap(proc = Undefined, &block) click to toggle source

Lifts a block/proc over Valid

@overload fmap(proc)

@param proc [#call]
@return [Validated::Valid]

@overload fmap

@param block [Proc]
@return [Validated::Valid]
# File lib/dry/monads/validated.rb, line 102
def fmap(proc = Undefined, &block)
  f = Undefined.default(proc, block)
  self.class.new(f.(value!))
end
inspect() click to toggle source

@return [String]

# File lib/dry/monads/validated.rb, line 122
def inspect
  if Unit.equal?(@value)
    "Valid()"
  else
    "Valid(#{@value.inspect})"
  end
end
Also aliased as: to_s
or(_ = nil) click to toggle source

Ignores arguments, returns self

@return [Validated::Valid]

# File lib/dry/monads/validated.rb, line 117
def or(_ = nil)
  self
end
to_maybe() click to toggle source

Converts to Maybe::Some

@return [Maybe::Some]

# File lib/dry/monads/maybe.rb, line 436
def to_maybe
  Maybe.pure(value!)
end
to_result() click to toggle source

Converts to Result::Success

@return [Result::Success]

# File lib/dry/monads/result.rb, line 463
def to_result
  Result.pure(value!)
end
to_s()
Alias for: inspect
value!() click to toggle source

Extracts the value

@return [Object]

# File lib/dry/monads/validated.rb, line 68
def value!
  @value
end