Skip to content

[SR-12842] Restore missing docs for RangeExpression.~= #31907

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 20, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions stdlib/public/core/Range.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,25 @@ public protocol RangeExpression {
}

extension RangeExpression {

/// Returns a Boolean value indicating whether a value is included in a
/// range.
///
/// You can use the pattern-matching operator (`~=`) to test whether a value
/// is included in a range. The pattern-matching operator is used
/// internally in `case` statements for pattern matching. The following
/// example uses the `~=` operator to test whether an integer is included in
/// a range of single-digit numbers:
///
/// let chosenNumber = 3
/// if 0..<10 ~= chosenNumber {
/// print("\(chosenNumber) is a single digit.")
/// }
/// // Prints "3 is a single digit."
///
/// - Parameters:
/// - pattern: A range.
/// - bound: A value to match against `pattern`.
@inlinable
public static func ~= (pattern: Self, value: Bound) -> Bool {
return pattern.contains(value)
Expand Down