Strideable

extension Strideable where Stride: SignedInteger

Available where Stride: SignedInteger

  • Limit a value to the specified range.

    4.clamped(to: 1..<10) // 4
    11.clamped(to: 1..<10) // 10
    0.clamped(to: 1..<10) // 1
    

    Declaration

    Swift

    public func clamped(to limits: CountableClosedRange<Self>) -> Self

    Parameters

    limits

    Bounds of alowable values.

    Return Value

    The clamped value