Last active
April 10, 2019 09:08
-
-
Save daehn/c41bbb372342c4da4620fef3efcbff88 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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