import Foundation | |
extension Equatable { | |
/// Whether `self` is contained in a list of other values. | |
/// Variadic version, see the method below for the generic implementation. | |
/// | |
/// - Parameter others: The values that `self` should be checked against. | |
/// - Returns: Whether or not `self` is one of the provided other values. | |
func isOne(of others: Self...) -> Bool { | |
return isOne(of: others) | |
} | |
/// Whether `self` is contained in a list of other values. | |
/// Non-variadic version that accepts any sequence of the same type. | |
/// | |
/// - Parameter others: The values that `self` should be checked against. | |
/// - Returns: Whether or not `self` is one of the provided other values. | |
func isOne<T: Sequence>(of others: T) -> Bool where T.Element == Self { | |
return others.contains(self) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment