Skip to content

Instantly share code, notes, and snippets.

@daehn
Last active April 10, 2019 09:08
Show Gist options
  • Save daehn/c41bbb372342c4da4620fef3efcbff88 to your computer and use it in GitHub Desktop.
Save daehn/c41bbb372342c4da4620fef3efcbff88 to your computer and use it in GitHub Desktop.
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