deckarep (2) [Avatar] Offline
#1
In GoInAction - page 107, Listing 4.46,

There is an example where a slice is used as a key which yields a compiler exception: invalid map key type []string

Perhaps it may be beneficial to callout that function types also cannot be used as keys to a map. I know it's somewhat of an unusual case, but perhaps it's important seeing as Go's functions are first class citizens.

See this example:
http://play.golang.org/p/B6y_DeU6Qq
Bill Kennedy (69) [Avatar] Offline
#2
Re: GoInAction - page 107, Listing 4.46
Let me run this through the guys. But yes this is an interesting example. Thanks!!
deckarep (2) [Avatar] Offline
#3
Re: GoInAction - page 107, Listing 4.46
There is another situation where map keys are invalid. That is if you have a custom type that also has a slice field.

http://play.golang.org/p/U3bq4iSHpg

I believe this is invalid because equality is not defined on types that have slices. Also, if this were possible and the slice were mutated it would invalidate the hash of the type already in the map when trying to find it. This is more theoretical, but at least Go doesn't allow it for good reasons.
Bill Kennedy (69) [Avatar] Offline
#4
Re: GoInAction - page 107, Listing 4.46
Reading your comments again you were absolutely correct. Thanks for taking the time to write this up and start a conversation around it.