3 points | by mtlynch 3 hours ago ago
1 comments
A fun quirk about Go that nobody tells you about is that a function with multiple return values can supply multiple arguments. So this:
func must[T any](t T, err error) T { if err != nil { panic(err) } return t } func makeInt(i int) (int, error) { if i == 0 { return 0, fmt.Errorf("not zero") } return i, nil } func main() { i := must(makeInt(3)) }
A fun quirk about Go that nobody tells you about is that a function with multiple return values can supply multiple arguments. So this:
is totally legal & works exactly how you'd expect it to!