Skip to content

lift(_:into:)

mattpolzin edited this page Oct 1, 2020 · 2 revisions

lift(_:into:)

Lift the value the KeyPath points to into any number of validations on that value producing a new validation function that operates on the type of the root of the KeyPath and results in all the given validations being run.

public func lift<T, U>(_ path: KeyPath<ValidationContext<T>, U>, into validations: Validation<U>) -> (ValidationContext<T>) -> [ValidationError]

This can be used to perform logic such as: "When type A has property b of type String with value 'hello', run validations alpha and beta (both of which are Validations on type String"

Example

let alpha = Validator<String>(...)
let beta = Validator<String>(...)

let validator = Validator<A>(
    check: lift(\.a, into: alpha, beta),
    when: \.a == "hello"
)

lift(_:into:)

Lift the value the KeyPath points to into any number of validations on that value producing a new validation function that operates on the type of the root of the KeyPath and results in all the given validations being run.

public func lift<T, U>(_ path: KeyPath<T, U>, into validations: Validation<U>) -> (ValidationContext<T>) -> [ValidationError]

This can be used to perform logic such as: "When type A has property b of type String with value 'hello', run validations alpha and beta (both of which are Validations on type String"

Example

let alpha = Validator<String>(...)
let beta = Validator<String>(...)

let validator = Validator<A>(
    check: lift(\.a, into: alpha, beta),
    when: \.a == "hello"
)
Types
Protocols
Global Functions
Extensions
Clone this wiki locally