Dave, > I’m ok with doing it as an extension on `Comparable`, although we should > add an overload for regular ranges, too.
Yeah, I completely agree and for now I'll drop the topic of removing the global definitions for min / max. So the aim of this proposal would be to add `clamp` to both `Range` and `Comparable`. - Nick On Fri, Mar 10, 2017 at 6:16 PM, David Sweeris <daveswee...@mac.com> wrote: > > 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