> On Mar 10, 2017, at 1:12 AM, Nicholas Maccharoli via swift-evolution > <swift-evolution@swift.org> wrote: > > Sorry for sidetracking by talking about dumping the global definitions of > `min` and `max` but if that could be done and it were decided by the swift > community that adding a clamp function would be appropriate, I guess with the > array implementations of min / max the clamp function might be implemented > like this? > > extension Comparable { > > func clamped(to range: ClosedRange<Self>) -> Self { > > return [range.lowerBound, [self, range.upperBound].min()!].max()! > > } > > } > I’m ok with doing it as an extension on `Comparable`, although we should add an overload for regular ranges, too.
- Dave Sweeris
_______________________________________________ swift-evolution mailing list swift-evolution@swift.org https://lists.swift.org/mailman/listinfo/swift-evolution