class Dry::Types::Definition

def try(input, &block)

Returns:
  • (nil) - otherwise
  • (Result, Logic::Result) - when a block is not provided

Other tags:
    Yieldreturn: -

Other tags:
    Yieldparam: failure -

Parameters:
  • block (#call, nil) --
  • input (Object) --
def try(input, &block)
  if valid?(input)
    success(input)
  else
    failure = failure(input, "#{input.inspect} must be an instance of #{primitive}")
    block ? yield(failure) : failure
  end
end