On 11 October 2017 at 18:30, Mike Kluev <[email protected]> wrote:
> > On 7 Oct 2017, at 04:24, Chris Lattner via swift-evolution < > [email protected]> wrote: > >> > >> >> 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. >> > > or make it a non-initialiser: let x = Int.random or Int.random() > on the positive side would be ability to omit types in many cases: foo(_ x: Int) { ... } foo(.random) // Int.random inferred > have you guys considered: func random<T>(...) -> T > where it returns a different type based on a context? > or "foo(random())" here, random<Int>() inferred the latter case opens wide opportunities for strict type/range checking, e.g.: if "angle" is a variable ranging from 0 .. 2*pi then angle = random() // is inferred as a 0 .. 2*pi range without me typing anything Mike
_______________________________________________ swift-evolution mailing list [email protected] https://lists.swift.org/mailman/listinfo/swift-evolution
