> On Oct 4, 2017, at 9:12 PM, Chris Lattner via swift-evolution 
> <[email protected]> wrote:
> 
>> ```
>> extension Int {
>>   static func random(in range: Countable{Closed}Range<Int>) -> Int
>> }
> 
> Nice.  Should these be initializers like:
> 
> extension Int {
>   init(randomIn: Countable{Closed}Range<Int>)
> }
> 

I don’t see much of a case for making it it random(in: SpecificCollection) 
instead of genericCollection.random().

One possible reason is if you exclude half-open ranges, only having 
CountableClosedRange, then you don’t have to account for the possibility of an 
empty collection (via an optional or a trap) because they cannot be empty. But 
closed ranges aren’t the currency type – half-open ranges are. So it’d hit 
usability if you have to convert from one to t'other often.

Other possibility is discovery. But given the common use case is “random 
element from collection”, I don’t expect this to be an issue as it will quickly 
become common knowledge that this feature is available.


_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to