[swift-evolution] [Proposal] Random Unification
tali at admingilde.org
Thu Nov 30 17:59:34 CST 2017
>>> This is redundant. In order to pick a random element, you’re saying I should have to do “Int.random(0 ..< 10)”? The redundancy here is that I have to specify Int twice: once for the “.random” call, and again for the type of the range. We can do better than that.
> I don’t see how this is redundant—do you mean that you’d need to write out the type name instead of writing `(0..<10).random()!`? I continue to be of the opinion that picking a random integer/floating-point value/Boolean and picking a random element from a collection are two different operations.
Well, I don‘t see a big difference beteeen ranges and collections here. We can support both with the same syntax:
let a = random.draw(from: 1...3)
let b = random.draw(from: [1, 2, 3])
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the swift-evolution