Using map[string]int as parameter of type map[interface{}]interface{}

A solution to your problem, simply initiate the map as an empty interface of empty interfaces:

m := map[interface{}]interface{}

then you can assign any type key or value you want in the 'ReturnTuples' function.

playground example

NOTE: remember that if you want to use the values later as the original types, you will need to use type assertion because now they are of type interface{}

You may do something this like this, were anything is one map value which you can get using a for loop:

switch v := anything.(type) {
      case string:
            fmt.Println(v)
      case int32, int64:
            fmt.Println(v)
      case string:
            fmt.Println(v)
      case SomeCustomType:
            fmt.Println(v)
      default:
            fmt.Println("unknown")
}

If you are looking for an explanation for the "why" @ymonad gave a full answer so I wont repeat it again.

hope it make sense

PS: don't get the down votes on the question, a legit one in my eyes...

Tags:

Go