Validation
public struct Validation<Value>
A struct for encapsulating validations.
-
Undocumented
Declaration
Swift
public typealias Validate = (_ value: Value) throws -> Void -
Undocumented
Declaration
Swift
public let validate: Validate
-
Initialize a new
Validationinstance.Declaration
Swift
public init(_ validate: @escaping Validate)Parameters
validateA
Validation.Validateclosure.
-
Undocumented
Declaration
Swift
typealias CountGreaterThanErrorMessageBuilder = (_ minimum: Int) -> String -
Validate a collection’s count is greater than a minimum amount.
Declaration
Swift
static func count<T: Collection>( greaterThan minimum: Int, message: CountGreaterThanErrorMessageBuilder? = nil ) -> Validation<T>Parameters
greaterThanThe minimum amount.
messageClosure to build custom error message.
Return Value
A Validation instance.
-
Validate an optional collection’s count is greater than a minimum amount.
If the value is nil, it is considered invalid.
Declaration
Swift
static func count<T: Collection>( greaterThan minimum: Int, message: CountGreaterThanErrorMessageBuilder? = nil ) -> Validation<Optional<T>>Parameters
greaterThanThe minimum amount.
messageClosure to build custom error message.
Return Value
A Validation instance.
-
Undocumented
Declaration
Swift
typealias CountLessThanErrorMessageBuilder = (_ maximum: Int) -> String -
Validate a collection’s count is less than a maximum amount.
Declaration
Swift
static func count<T: Collection>( lessThan maximum: Int, message: CountLessThanErrorMessageBuilder? = nil ) -> Validation<T>Parameters
lessThanThe maximum amount.
messageClosure to build custom error message.
Return Value
A Validation instance.
-
Validate a collection’s count is less than a maximum amount.
If the value is nil, it is considered invalid.
Declaration
Swift
static func count<T: Collection>( lessThan maximum: Int, message: CountLessThanErrorMessageBuilder? = nil ) -> Validation<Optional<T>>Parameters
lessThanThe maximum amount.
messageClosure to build custom error message.
Return Value
A Validation instance.
-
Undocumented
Declaration
Swift
typealias CountEqualToErrorMessageBuilder = (_ value: Int) -> String -
Validate a collection’s count is equal to an amount.
Declaration
Swift
static func count<T: Collection>( equalTo count: Int, message: CountEqualToErrorMessageBuilder? = nil ) -> Validation<T>Parameters
equalToThe value to be equal to.
messageClosure to build custom error message.
Return Value
A Validation instance.
-
Validate an optional collection’s count is equal to an amount.
If the value is nil, it is considered invalid.
Declaration
Swift
static func count<T: Collection>( equalTo count: Int, message: CountEqualToErrorMessageBuilder? = nil ) -> Validation<Optional<T>>Parameters
equalToThe value to be equal to.
messageClosure to build custom error message.
Return Value
A Validation instance.
-
Undocumented
Declaration
Swift
typealias CountRangeErrorMessageBuilder = (_ range: ClosedRange<Int>) -> String -
Validate a collection’s count is in a range.
Declaration
Swift
static func count<T: Collection>( in range: ClosedRange<Int>, message: CountRangeErrorMessageBuilder? = nil ) -> Validation<T>Parameters
equalToThe value to be equal to.
messageClosure to build custom error message.
Return Value
A Validation instance.
-
Validate an optional collection’s count is in a range.
If the value is nil, it is considered invalid.
Declaration
Swift
static func count<T: Collection>( in range: ClosedRange<Int>, message: CountRangeErrorMessageBuilder? = nil ) -> Validation<Optional<T>>Parameters
equalToThe value to be equal to.
messageClosure to build custom error message.
Return Value
A Validation instance.
-
Validate a string matches a regular expression.
Declaration
Swift
static func format( _ pattern: String, options: NSRegularExpression.Options = [], message: String? = nil ) -> Validation<String>Parameters
patternThe regular expression pattern.
optionsThe regular expression options that are applied to the expression during matching. See NSRegularExpression.Options for possible values.
messageCustom error message.
Return Value
A Validation
instance. -
Validate an optional string matches a regular expression.
Declaration
Swift
static func format( _ pattern: String, options: NSRegularExpression.Options = [], message: String? = nil ) -> Validation<Optional<String>>Parameters
patternThe regular expression pattern.
optionsThe regular expression options that are applied to the expression during matching. See NSRegularExpression.Options for possible values.
messageCustom error message.
Return Value
A Validation
instance. -
Validate an optional value is present.
If the value is nil, it is considered invalid.
Declaration
Swift
static func presence<T>( message: String? = nil ) -> Validation<Optional<T>>Parameters
messageA custom error message.
Return Value
A Validation instance.
-
Validate an optional string is present.
If the value is nil, it is considered invalid.
When
allowEmptyistruethe string""is valid. WhenallowEmptyisfalsethe string""is not valid.Declaration
Swift
static func presence( allowEmpty: Bool = false, message: String? = nil ) -> Validation<Optional<String>>Parameters
allowEmptyIndicate whether an empty string validates as present.
messageA custom error message.
Return Value
A Validation instance.
-
Validate a string is not empty.
As the string is not optional, this presence validation checks the string is not empty.
Declaration
Swift
static func presence( message: String? = nil ) -> Validation<String>Parameters
messageA custom error message.
Return Value
A Validation instance.
Validation Structure Reference