<commit_before>//
//  Created by <NAME> on 07.05.19.
//  Copyright © 2019 Flinesoft. All rights reserved.
//

import Foundation

extension Comparable {
    // MARK: - Clamp: Returning Variants
    /// Returns `self` clamped to the given limits.
    ///
    /// - Parameter limits: The closed range determining minimum & maxmimum value.
    /// - Returns:
    ///     - `self`, if it is inside the given limits.
    ///     - `lowerBound` of the given limits, if `self` is smaller than it.
    ///     - `upperBound` of the given limits, if `self` is greater than it.
    public func clamped(to limits: ClosedRange<Self>) -> Self {
        return limits.lowerBound > self ? limits.lowerBound
            : limits.upperBound < self ? limits.upperBound
            : self
        // swiftlint:disable:last too_much_unindentation
    }

    /// Returns `self` clamped to the given limits.
    ///
    /// - Parameter limits: The partial range (from) determining the minimum value.
    /// - Returns:
    ///     - `self`, if it is inside the given limits.
    ///     - `lowerBound` of the given limits, if `self` is smaller than it.
    public func clamped(to limits: PartialRangeFrom<Self>) -> Self {
        return limits.lowerBound > self ? limits.lowerBound
            : self
        // swiftlint:disable:last too_much_unindentation
    }

    /// Returns `self` clamped to the given limits.
    ///
    /// - Parameter limits: The partial range (through) determining the maximum value.
    /// - Returns:
    ///     - `self`, if it is inside the given limits.
    ///     - `upperBound` of the given limits, if `self` is greater than it.
    public func clamped(to limits: PartialRangeThrough<Self>) -> Self {
        return limits.upperBound < self ? limits.upperBound
            : self
        // swiftlint:disable:last too_much_unindentation
    }

    // MARK: Mutating Variants
    /// Clamps `self` to the given limits.
    ///
    /// - `self`, if it is inside the given limits.
    /// - `lowerBound` of the given limits, if `self` is smaller than it.
    /// - `upperBound` of the given limits, if `self` is greater than it.
    ///
    /// - Parameter limits: The closed range determining minimum & maxmimum value.
    public mutating func clamp(to limits: ClosedRange<Self>) {
        self = clamped(to: limits)
    }

    /// Clamps `self` to the given limits.
    ///
    /// - `self`, if it is inside the given limits.
    /// - `lowerBound` of the given limits, if `self` is smaller than it.
    ///
    /// - Parameter limits: The partial range (from) determining the minimum value.
    public mutating func clamp(to limits: PartialRangeFrom<Self>) {
        self = clamped(to: limits)
    }

    /// Clamps `self` to the given limits.
    ///
    /// - `self`, if it is inside the given limits.
    /// - `upperBound` of the given limits, if `self` is greater than it.
    ///
    /// - Parameter limits: The partial range (through) determining the maximum value.
    public mutating func clamp(to limits: PartialRangeThrough<Self>) {
        self = clamped(to: limits)
    }
}
<commit_msg>Use plain if / else pattern instead of (nested) ternary expressions<commit_after>//
//  Created by <NAME> on 07.05.19.
//  Copyright © 2019 Flinesoft. All rights reserved.
//

import Foundation

extension Comparable {
    // MARK: - Clamp: Returning Variants
    /// Returns `self` clamped to the given limits.
    ///
    /// - Parameter limits: The closed range determining minimum & maxmimum value.
    /// - Returns:
    ///     - `self`, if it is inside the given limits.
    ///     - `lowerBound` of the given limits, if `self` is smaller than it.
    ///     - `upperBound` of the given limits, if `self` is greater than it.
    public func clamped(to limits: ClosedRange<Self>) -> Self {
        if limits.lowerBound > self {
            return limits.lowerBound
        } else if limits.upperBound < self {
            return limits.upperBound
        } else {
            return self
        }
    }

    /// Returns `self` clamped to the given limits.
    ///
    /// - Parameter limits: The partial range (from) determining the minimum value.
    /// - Returns:
    ///     - `self`, if it is inside the given limits.
    ///     - `lowerBound` of the given limits, if `self` is smaller than it.
    public func clamped(to limits: PartialRangeFrom<Self>) -> Self {
        if limits.lowerBound > self {
            return limits.lowerBound
        } else {
            return self
        }
    }

    /// Returns `self` clamped to the given limits.
    ///
    /// - Parameter limits: The partial range (through) determining the maximum value.
    /// - Returns:
    ///     - `self`, if it is inside the given limits.
    ///     - `upperBound` of the given limits, if `self` is greater than it.
    public func clamped(to limits: PartialRangeThrough<Self>) -> Self {
        if limits.upperBound < self {
            return limits.upperBound
        } else {
            return self
        }
    }

    // MARK: Mutating Variants
    /// Clamps `self` to the given limits.
    ///
    /// - `self`, if it is inside the given limits.
    /// - `lowerBound` of the given limits, if `self` is smaller than it.
    /// - `upperBound` of the given limits, if `self` is greater than it.
    ///
    /// - Parameter limits: The closed range determining minimum & maxmimum value.
    public mutating func clamp(to limits: ClosedRange<Self>) {
        self = clamped(to: limits)
    }

    /// Clamps `self` to the given limits.
    ///
    /// - `self`, if it is inside the given limits.
    /// - `lowerBound` of the given limits, if `self` is smaller than it.
    ///
    /// - Parameter limits: The partial range (from) determining the minimum value.
    public mutating func clamp(to limits: PartialRangeFrom<Self>) {
        self = clamped(to: limits)
    }

    /// Clamps `self` to the given limits.
    ///
    /// - `self`, if it is inside the given limits.
    /// - `upperBound` of the given limits, if `self` is greater than it.
    ///
    /// - Parameter limits: The partial range (through) determining the maximum value.
    public mutating func clamp(to limits: PartialRangeThrough<Self>) {
        self = clamped(to: limits)
    }
}

{'fraction_non_alphanumeric': 0.11848190081326743, 'fraction_numerical': 0.0031892840057407114, 'mean_word_length': 2.0226506024096387, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3869192', 'n_tokens_mistral': 1768, 'n_tokens_neox': 1723, 'n_words': 673}