Re: [swift-evolution] [Idea] Add `bounds` function to standard library

2016-09-01 Thread Karl via swift-evolution
> On 2 Sep 2016, at 06:14, Xiaodi Wu wrote: > > Run loop modes are named by string, and as you can see in your link, > comparisons of run loop modes are by their raw value--i.e. by string. While > it's of course sensible to have a total ordering for strings, I'm skeptical > that you would typ

Re: [swift-evolution] [Idea] Add `bounds` function to standard library

2016-09-01 Thread Xiaodi Wu via swift-evolution
Run loop modes are named by string, and as you can see in your link, comparisons of run loop modes are by their raw value--i.e. by string. While it's of course sensible to have a total ordering for strings, I'm skeptical that you would typically want to get the "maximum" of two strings, and I'm not

Re: [swift-evolution] [Idea] Add `bounds` function to standard library

2016-09-01 Thread Karl via swift-evolution
> On 31 Aug 2016, at 15:53, Xiaodi Wu wrote: > > Comparable makes semantic guarantees about how values of conforming types > might be ordered. You don't need `min` or `max` for that to be useful, since > it's trivial to implement using comparison operators. > > Basic numeric types require com

Re: [swift-evolution] [Idea] Add `bounds` function to standard library

2016-08-31 Thread Dominik Pich via swift-evolution
I agree with karl. there is nothing really mathematical with min/max e.g. find the longest sequence of characters in a string or the smallest array or the minimal x coordinate of view objects… min/max/clamp are needed everywhere. LG Dominik Web: https://pich.info Twitter: @DaijDjan Facebook: Do

Re: [swift-evolution] [Idea] Add `bounds` function to standard library

2016-08-31 Thread Xiaodi Wu via swift-evolution
Comparable makes semantic guarantees about how values of conforming types might be ordered. You don't need `min` or `max` for that to be useful, since it's trivial to implement using comparison operators. Basic numeric types require compiler magic and thus belong in the standard library. Likewise,

Re: [swift-evolution] [Idea] Add `bounds` function to standard library

2016-08-31 Thread Karl via swift-evolution
> On 30 Aug 2016, at 10:18, Xiaodi Wu via swift-evolution > wrote: > > As an additive proposal, I don't think this would be in scope for the current > phase of Swift 4. > > Looking forward, though, I'm not sure this belongs in the standard library. > In general, my understanding is that Swif

Re: [swift-evolution] [Idea] Add `bounds` function to standard library

2016-08-30 Thread Xiaodi Wu via swift-evolution
As an additive proposal, I don't think this would be in scope for the current phase of Swift 4. Looking forward, though, I'm not sure this belongs in the standard library. In general, my understanding is that Swift's standard library is deliberately small, and that the criteria for additions are t

Re: [swift-evolution] [Idea] Add `bounds` function to standard library

2016-08-29 Thread Nicholas Maccharoli via swift-evolution
Tim, The protocol extension alone would be sufficient, but for as long as the global functions `min` and `max` are still around I thought adding a global clamp function would make for good symmetry. I'll write a small draft proposal to illustrate my idea a little better. What does the community

[swift-evolution] [Idea] Add `bounds` function to standard library

2016-08-29 Thread Tim Vermeulen via swift-evolution
What would the point of a free function be if you already have a protocol extension? > Georgios, Yes lets go with clamp for a name! > > Pyry, Originally I thought of just adding a global function akin to `min` > and `max` but I am also > in favour of adding the above extension to `Comparable`. >

Re: [swift-evolution] [Idea] Add `bounds` function to standard library

2016-08-29 Thread Nicholas Maccharoli via swift-evolution
Georgios, Yes lets go with clamp for a name! Pyry, Originally I thought of just adding a global function akin to `min` and `max` but I am also in favour of adding the above extension to `Comparable`. I think having both the global function and the protocol extension for `clamp` would be great. -

Re: [swift-evolution] [Idea] Add `bounds` function to standard library

2016-08-25 Thread Pyry Jahkola via swift-evolution
> On 25 Aug 2016, at 12:05, Nicholas Maccharoli wrote: > > I personally see merit in adding a function to bound the value of a variable > within a range and think it would be simple to write with the existing > implementations of `min` and `max` with something like: > > public func bounds(v

[swift-evolution] [Idea] Add `bounds` function to standard library

2016-08-25 Thread Georgios Moschovitis via swift-evolution
> In the standard library there is a `min` and a `max` function but there isn't > a `bounds` function, or a function that takes a value and an upper and lower > bound and returns that value if it is Perhaps ‘clamp’ would be a better name? ___ swift-evo

[swift-evolution] [Idea] Add `bounds` function to standard library

2016-08-25 Thread Nicholas Maccharoli via swift-evolution
Swift Evolution Community, In the standard library there is a `min` and a `max` function but there isn't a `bounds` function, or a function that takes a value and an upper and lower bound and returns that value if it is within the specified range or if not the closer of the lower or upper values s