[swift-evolution] Proposal: Tuple Convertible
John McCall
rjmccall at apple.com
Mon Dec 7 00:02:25 CST 2015
> On Dec 6, 2015, at 4:07 PM, Nikolai Vazquez via swift-evolution <swift-evolution at swift.org> wrote:
> I was thinking it could work for variables that are already tuples but then that goes against Swift's strict typing. So really it should only be for tuple literals.
>
I think this is an interesting idea, but I believe it’s not actually expressible in the current generics system without hard-coding the protocol to just 2-tuples.
John.
>
> On Sun, Dec 6, 2015, 7:01 PM Stephen Celis <stephen.celis at gmail.com <mailto:stephen.celis at gmail.com>> wrote:
> Do you mean a TupleLiteralConvertible? I’m also in favor of a ClosureLiteralConvertible (or FunctionLiteralConvertible).
>
> Stephen
>
>
>> On Dec 6, 2015, at 6:40 PM, Nikolai Vazquez via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>>
>
>> When working with points, I’ll sometimes make a typealias to an integer tuple:
>>
>> typealias Point = (x: Int, y: Int)
>> However, if I want to add extended functionality to my Point type, I would have to change it to a struct, removing the ability to create one on the fly with a tuple.
>>
>> I’m proposing a TupleConvertible protocol that allows initialization from a tuple directly.
>>
>> struct Point: TupleConvertible {
>>
>> var x, y: Int
>>
>> init(x: Int, y: Int) {
>> self.x = x
>> self.y = y
>> }
>>
>> init(tuple: (x: Int, y: Int)) {
>> self.init(x: tuple.x, y: tuple.y)
>> }
>>
>> }
>> This would make it very easy to create new Point instances.
>>
>> let somePoint: Point = (50, 120)
>> let otherPoint = Point(x: 50, y: 120)
>
>> _______________________________________________
>> swift-evolution mailing list
>> swift-evolution at swift.org <mailto:swift-evolution at swift.org>
>> https://lists.swift.org/mailman/listinfo/swift-evolution <https://lists.swift.org/mailman/listinfo/swift-evolution>
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org <mailto:swift-evolution at swift.org>
> https://lists.swift.org/mailman/listinfo/swift-evolution <https://lists.swift.org/mailman/listinfo/swift-evolution>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151206/930a7940/attachment.html>
More information about the swift-evolution
mailing list