[swift-evolution] Proposal: Tuple Convertible
Stephen Celis
stephen.celis at gmail.com
Sun Dec 6 18:01:23 CST 2015
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> 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
> 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/4a56088d/attachment.html>
More information about the swift-evolution
mailing list