Added AssignmentPrecedence precedence to <~ operator. Use Validations.run(_:) method to run validations on the new value

This commit is contained in:
Caleb Kleveter 2018-11-28 14:25:01 -06:00
parent c1d9ba9ef8
commit ad1e67aabd
No known key found for this signature in database
GPG Key ID: B38DBD5CF2C98D69
1 changed files with 4 additions and 5 deletions

View File

@ -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
}