Created
April 21, 2017 03:21
-
-
Save nahive/7fa924ba79ce6b226156b39015f46b85 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
extension Comparable { | |
/// Returns a Boolean value indicating whether a value is included in a | |
/// range. | |
/// | |
/// You can use this pattern matching operator (`~=`) to test whether a value | |
/// is included in a range. The following example uses the `~=` operator to | |
/// test whether an integer is included in a range of single-digit numbers. | |
/// | |
/// let chosenNumber = 3 | |
/// if chosenNumber ~= 0...9 { | |
/// print("\(chosenNumber) is a single digit.") | |
/// } | |
/// // Prints "3 is a single digit." | |
/// | |
/// - Parameters: | |
/// - lhs: A value to match against `rhs`. | |
/// - rhs: A range. | |
public static func ~=(lhs: Self, rhs: ClosedRange<Self>) -> Bool { | |
return rhs ~= lhs | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment