Skip to content

Commit 9ee5911

Browse files
authored
Merge pull request #31907 from gwynne/sr-12842-range-pattern-match-op-missing-docs
[SR-12842] Restore missing docs for RangeExpression.~=
2 parents 961764a + 3ae3a7b commit 9ee5911

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

stdlib/public/core/Range.swift

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,25 @@ public protocol RangeExpression {
7474
}
7575

7676
extension RangeExpression {
77+
78+
/// Returns a Boolean value indicating whether a value is included in a
79+
/// range.
80+
///
81+
/// You can use the pattern-matching operator (`~=`) to test whether a value
82+
/// is included in a range. The pattern-matching operator is used
83+
/// internally in `case` statements for pattern matching. The following
84+
/// example uses the `~=` operator to test whether an integer is included in
85+
/// a range of single-digit numbers:
86+
///
87+
/// let chosenNumber = 3
88+
/// if 0..<10 ~= chosenNumber {
89+
/// print("\(chosenNumber) is a single digit.")
90+
/// }
91+
/// // Prints "3 is a single digit."
92+
///
93+
/// - Parameters:
94+
/// - pattern: A range.
95+
/// - bound: A value to match against `pattern`.
7796
@inlinable
7897
public static func ~= (pattern: Self, value: Bound) -> Bool {
7998
return pattern.contains(value)

0 commit comments

Comments
 (0)