Skip to content

all(_:)

mattpolzin edited this page Dec 20, 2020 · 1 revision

all(_:)

Apply all of the given validations to the current context.

public func all<T>(_ validations: Validation<T>) -> (ValidationContext<T>) -> [ValidationError]

This is equivalent to calling lift with the keypath \.self or inlining each of the individual validations with the && operator to apply them all. The benefit to this approach is being able to create reusable separate components that add up to the validation being written.

Example

let isLongerThanThreeChars = Validator<String>(...)
let hasSpecialChars = Validator<String>(...)

let validator = Validator<String>(
    check: all(isLongerThanThreeChars, hasSpecialChars)
)
Types
Protocols
Global Functions
Extensions
Clone this wiki locally