Added AssignmentPrecedence precedence to <~ operator. Use Validations.run(_:) method to run validations on the new value
This commit is contained in:
parent
c1d9ba9ef8
commit
ad1e67aabd
|
@ -1,17 +1,16 @@
|
|||
infix operator <~
|
||||
infix operator <~: AssignmentPrecedence
|
||||
|
||||
/// Sets the stored value of a `Failable` type.
|
||||
///
|
||||
/// You have to use this operator instead of `=` so the validations always run on the new value before it is assigned.
|
||||
///
|
||||
/// - Note: Sub-validations are only run 1 level deep. This prevents any validation loops that could occur and saves on run time.
|
||||
///
|
||||
/// - Complexity: O(n), where _n_ is the number of type compatible sub-validations for the `Failable` type's sub-validations.
|
||||
/// - Complexity: O(n^m), where _n_ is the number of type compatible sub-validations for the `Failable` type's sub-validations
|
||||
/// and _m_ is the depth of the sub-validations.
|
||||
///
|
||||
/// - Parameters:
|
||||
/// - root: The `Failable` instance that holds the value to be mutated.
|
||||
/// - value: The new value for the `root.value` property.
|
||||
public func <~ <T, Validations>(root: inout Failable<T, Validations>, value: T)throws {
|
||||
try root.validate(value)
|
||||
try Validations.run(value)
|
||||
root.value = value
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue