Skip to content

proposal: Go 2: add tuple type #61920

Closed as not planned
Closed as not planned
@leaxoy

Description

@leaxoy

Go is lack of Tuple type since first release, variadic return variables can solve this in a strange way. (At least in my thinking, what's wrong can be pointed out)

Recently a series proposals to add iterator to go, and introduce a trick type Seq2, this make thing even worse, we can imagine that in the near future, there may lots of trick types in std library, this should be what everyone doesn't want to see.

So I propose add the long time missing type - Tuple to go, then the Seq2 can write to Seq[(K, V)], imagine () make a list type into tuple type.

Access tuple field using index number.

In function return values, we can treat it as tuple implicitly, so we can write this:

func x() (int, string) {
    ...
}

func y() {
    ret := x()
    print(ret.0)
    print(ret.1)
}

Related Iterator Proposal: #61897 and others ...

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions