Skip to content

lift(__into_)

mattpolzin edited this page Jun 11, 2021 · 1 revision

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