Created Failable[keyPath:] subscript

This commit is contained in:
Caleb Kleveter 2018-11-28 11:38:51 -06:00
parent 7795c0fb3e
commit c18712a618
No known key found for this signature in database
GPG Key ID: B38DBD5CF2C98D69
1 changed files with 7 additions and 0 deletions

View File

@ -35,6 +35,13 @@ public struct Failable<T, Validations> where Validations: Validation, Validation
try self <~ t
}
/// Gets the value of a property of the `value` property using a key path.
///
/// - Parameter path: The key path of the property to get from the `value` property.
public subscript<Value>(keyPath path: KeyPath<T, Value>) -> Value {
return self.value[keyPath: path]
}
internal func validate(_ value: T)throws {
try Validations.validate(value)
try Validations.safeSubvalidations.forEach { validation in try validation.validate(value) }