Is it possible in Go to unpack an array into several variables, for example, in Python.
for instance
var arr [4]string = [4]string {"X", "Y", "Z", "W"} x, y, z, w := arr
I found that this is not supported in Go. Is there anything I can do to not write x,y,z,w=arr[0],arr[1],arr[2],arr[3]
Moreover, is it possible to maintain something like
var arr []string = [4]string {"X", "Y", "Z", "W"} x, y, z, w := arr
Note that now this is a fragment instead of an array, so the compiler will implicitly check if len (arr) == 4 and report an error if not.
source share