Created == and != operators for comparing Failable<T> with T

This commit is contained in:
Caleb Kleveter 2019-01-23 10:09:51 -06:00
parent fde0c8669e
commit a11244d687
No known key found for this signature in database
GPG Key ID: B38DBD5CF2C98D69
1 changed files with 18 additions and 0 deletions

View File

@ -18,6 +18,15 @@ public func == <T, V1, V2>(lhs: Failable<T, V1>, rhs: Failable<T, V2>) -> Bool w
return lhs.value == rhs.value
}
/// Checks for equality of the `value` property from one `Failable` instances with another value of type `T`.
///
/// - Parameters:
/// - lhs: The `Failable` instance to compare.
/// - rhs: The `T` value to compare.
public func == <T, V1>(lhs: Failable<T, V1>, rhs: T) -> Bool where T: Equatable {
return lhs.value == rhs
}
/// Checks for inequality of the `value` property from two `Failable` instances where type `T` is the same and comforms to `Equatable`,
/// but the `Validations` are different.
///
@ -28,6 +37,15 @@ public func != <T, V1, V2>(lhs: Failable<T, V1>, rhs: Failable<T, V2>) -> Bool w
return lhs.value != rhs.value
}
/// Checks for inequality of the `value` property from one `Failable` instances with another value of type `T`.
///
/// - Parameters:
/// - lhs: The `Failable` instance to compare.
/// - rhs: The `T` value to compare.
public func != <T, V1>(lhs: Failable<T, V1>, rhs: T) -> Bool where T: Equatable {
return lhs.value != rhs
}
// MARK: - Comparable
extension Failable: Comparable where T: Comparable {