Given swap
, a function that returns multiple values, and supposing it's part of some API I can't modify:
package main
import "fmt"
func swap(x, y string) (string, string) {
return y, x
}
func main() {
a, b := swap("hello", "world")
fmt.Println(a, b)
}
Is it possible to use swap
function and get only the first returned value, discarding the second one? I tried this:
func main() {
a, b := swap("hello", "world")
fmt.Println(a)
}
ERROR: prog.go:10: b declared and not used [process exited with non-zero status]
And this is not possible too:
a := swap("hello", "world")
ERROR: prog.go:10: multiple-value swap() in single-value context
How to deal with functions that return multiple values when I don't need all the returned parts?
Code is based on "A tour of go - lesson 9"