Ben Chuanlong Du's Blog

It is never too late to learn.

Tuple in Golang

Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!

Tips and Traps

  1. Golang implements the type Tuple in the standard library go/types, however, Tuple is NOT a first class citizen in Golang.

  2. Multiple return parameters in Golang is implemented via Tuple in a limited way (since Tuple is not a first-class citizen).

    • Tuple can only be used as multiple return parameters/values currently.

    • Since Tuple is not a first-class citizen, you cannot use a Tuple to receive multiple return values. Instead, you have to use define multiple variables to receive multiple return values.

    • Nested types is NOT allowed as return parameters.

In [7]:
import "go/types"
In [8]:
types.Tuple
repl.go:1:1: package types "go/types" has no symbol Tuple
In [ ]:
 

Comments