Comparable

public extension Comparable
  • SwifterSwift: Returns true if value is in the provided range.

    1.isBetween(5…7) // false 7.isBetween(6…12) // true date.isBetween(date1…date2) “c”.isBetween(a…d) // true 0.32.isBetween(0.31…0.33) // true

    Declaration

    Swift

    func isBetween(_ range: ClosedRange<Self>) -> Bool

    Parameters

    min

    Minimum comparable value.

    max

    Maximum comparable value.

    Return Value

    true if value is between min and max, false otherwise.

  • SwifterSwift: Returns value limited within the provided range.

    1.clamped(to: 3...8) // 3
    4.clamped(to: 3...7) // 4
    "c".clamped(to: "e"..."g") // "e"
    0.32.clamped(to: 0.1...0.29) // 0.29
    

    Declaration

    Swift

    func clamped(to range: ClosedRange<Self>) -> Self

    Parameters

    min

    Lower bound to limit the value to.

    max

    Upper bound to limit the value to.

    Return Value

    A value limited to the range between min and max.