[swift-evolution] Add clamp(value: Bound) -> Bound to ClosedInterval

Kevin Ballard kevin at sb.org
Wed Feb 17 17:51:08 CST 2016


I'd like to see ClosedInterval gain a new method

    /// Returns `value` clamped to `self`.
    func clamp(value: Bound) -> Bound

This can't go on HalfOpenInterval (and therefore can't go on IntervalType) because a half-open interval doesn't have a known largest-contained-value (and in fact it can be empty), but it's perfectly reasonable for ClosedInterval to have this.

-Kevin Ballard


More information about the swift-evolution mailing list