[swift-evolution] [Proposal] Random Unification

Mike Kluev mike.kluev at gmail.com
Wed Oct 11 12:30:14 CDT 2017


> On 7 Oct 2017, at 04:24, Chris Lattner via swift-evolution <
swift-evolution at swift.org> 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.
>

every now and then i found myself in a situation i want to use this
preferred way, and i need a label... but i do not have anything to pass,
e.g.:

let x = Int(random)                          // oops

has to resort to hacks: let x = Int(random: ())
or make it a non-initialiser: let x = Int.random or Int.random()

have you guys considered: func random<T>(...) -> T
where it returns a different type based on a context?

Mike
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20171011/96398b45/attachment.html>


More information about the swift-evolution mailing list