> On Oct 5, 2017, at 10:58 AM, Nate Cook via swift-evolution
> <[email protected]> wrote:
>
> The edge case is really the same (empty ranges), it’s about what we do with
> the edge case. If we include the methods on integer types, usage will look
> like this:
>
> let x = Int.random(in: 0..<5) // 3
> let y = Int.random(in: 0..<0) // runtime error
>
> If we only have the collection methods, usage will look like this:
>
> let x = (0..<5).random()! // 3
> let y = (0..<0).random()! // runtime error
These aren’t the forms I was suggesting, what I meant was:
extension Int {
init(randomInRange: Countable{Closed}Range<Int>)
}
which gives:
let x = Int(randomInRange: 0..<5)
The point of this is that you’re producing an Int (or whatever type).
Regardless of whether the initializer is failable or not, this is the preferred
way of creating a new value with some property: it is an initializer with a
label.
-Chris
_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution