Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

2
  • 2
    what is T in var v, ok T = a[x]? isn't ok must be bool? Commented May 12, 2017 at 4:31
  • 3
    @Kokizzu That's the general form of the variable declaration. At first we might think it would only work (compile) if the map would be of type map[bool]bool and T is bool, but it also works if map is of type map[interface{}]bool and T is interface{}; moreover it also works with custom types having bool as underlying type, see all on the Go Playground. So since that form is valid with multiple types substituted for T, that's why the general T is used. Type of ok can be anything to which an untyped bool can be assigned. Commented May 12, 2017 at 7:53