No, sorry, slices cannot be used as map keys. Also note that equality is not dependent on methods and not user changeable but solely determined by the language spec.
If you can derive e.g. a string from the slice and use that string as the map key you would be fine. V. On Tuesday, 22 May 2018 19:59:24 UTC+2, Sankar wrote: > > Is there a way to use a slice as a key to a map ? If I try, I get a > compilation error: `invalid map key type`. > > I tried creating a custom type, which contains an array as the element. > However, I could not find out what method to implement for my custom > type(such as: func (i *myType) Equal(j *myType) bool ) that would make the > equality operator call this function. > > An example program, where I needed to use a slice/array as the key of a > map is also available at: https://play.golang.org/p/kXwAaHckL76 > > Is there a way (or alternate solutions) to use a slice as the map key ? > > Thanks. > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.