Making tuples more useful with ExpressibleByTupleLiteral?

I had a similar idea a few months ago that might be a good way to tackle this. Assuming this Point struct:

struct Point {
    let x: Int
    let y: Int

    static let zero = Point(x: 0, y: 0)
}

We can already do this:

let p: Point = .init(x: 42, y: 420)

My idea would be to allow omitting the init part, leaving us with:

let p: Point = .(x: 42, y: 420)

Since the leading dot is already established as accessing a static member of the inferred type, I think this is quite a natural extension. Comparing the existing leading dot syntax with my proposed syntax:

let a1 = Point.zero
let a2: Point = .zero

let b1 = Point(x: 42, y: 420)
let b2: Point = .(x: 42, y: 420)

Imo, this would be more useful than normal tuples plus a protocol because you could use any initialiser, including extending existing types with your own. The leading dot also clearly distinguishes it from normal tuples, avoiding confusion.

3 Likes