Yup! That's right! At the end of the day i used the enums idioms
<https://stackoverflow.com/questions/14426366/what-is-an-idiomatic-way-of-representing-enums-in-go>,
employing integer type (the value that supports the "enum" )

(TL;DR;) Ancient History :

The problem arises as i get used to use maps in Java where you can use as a
key a class definition (that is custom data type in Java, like the same way
an "struct" in Golang is a custom data type). So i get use to work with
types as keys, that way i could associate logic and data with an
asbtraction (recall that logic and data does not intrinsically belong to
that abstraction, so it would be wrong to place all in there).

I wake-up in golang without that capability: i mean how i may refer to a
group of well know struct definitions in a generic way, i mean for example
this:

type Person struct {
}

var SpanishTermByStruct map[struct]string = map[struct]string{
Person: "person",
}

? and in that moment the wondering about using "type" for key (or value)
comes to my mind... i then i get that is not allowed.


El sáb., 26 ene. 2019 a las 10:57, <mountain...@gmail.com> escribió:

> I looked at your program example, mainly using the reflection type to
> design the mapped key, perhaps the reflected key is a comparable type, but
> I mainly propose specific types, such as func, slice, map can not be used
> as a key use
>
> 在 2019年1月25日星期五 UTC+8下午11:31:57,Victor Giordano写道:
>>
>> Yeah, i got the idea. I had already researched about it and what you can
>> do about it.
>> <https://stackoverflow.com/questions/50730331/mapping-concrete-types>
>> I was only repeating what i want as a dev in this community!
>>
>> El viernes, 25 de enero de 2019, 12:04:38 (UTC-3), Wagner Riffel escribió:
>>>
>>> you can "employ" any custom type as key but the ones that doesn't
>>> defines equality operations, see
>>> https://golang.org/ref/spec#Comparison_operators
>>> as Ian already pointed out, you just can't build your custom type on
>>> top of func, map or slice to be a valid key, anything else you can.
>>>
>>> On Fri, Jan 25, 2019 at 12:47 PM Victor Giordano <vituc...@gmail.com>
>>> wrote:
>>> >
>>> > Just wanna say : It would be nice to employ a custom type as a valid
>>> key for a map!!! :D
>>> >
>>> >
>>> > El jueves, 24 de enero de 2019, 0:47:32 (UTC-3), mount...@gmail.com
>>> escribió:
>>> >>
>>> >> thanks lan.
>>> >>
>>> >> 在 2019年1月23日星期三 UTC+8下午11:26:57,Ian Lance Taylor写道:
>>> >>>
>>> >>> On Tue, Jan 22, 2019 at 11:47 PM <mount...@gmail.com> wrote:
>>> >>> >
>>> >>> > i got :
>>> >>> >   # command-line-arguments
>>> >>> > ./key.go:6:18: invalid operation: F() == F() (func can only be
>>> compared to nil)
>>> >>>
>>> >>> Yes, that is what the language spec says and it is what I said: in
>>> Go,
>>> >>> function values are not comparable.
>>> >>>
>>> >>> I wrote that code as an example to help explain why function values
>>> >>> are not comparable.
>>> >>>
>>> >>> Ian
>>> >>>
>>> >>> > 在 2019年1月23日星期三 UTC+8上午11:59:07,mount...@gmail.com写道:
>>> >>> >>
>>> >>> >>      When i use the func, map slice as the key of map, it isn't
>>> work!
>>> >>> >>      So  I lookup source  why, i find
>>> >>> >>
>>> >>> >>     // spec: "The comparison operators == and != must be fully
>>> defined
>>> >>> >>         // for operands of the key type; thus the key type must
>>> not be a
>>> >>> >>         // function, map, or slice."
>>> >>> >>         //
>>> >>> >>         // Delay this check because it requires fully setup
>>> types;
>>> >>> >>         // it is safe to continue in any case (was issue 6667).
>>> >>> >>         check.later(func() {
>>> >>> >>             if !Comparable(typ.key) {
>>> >>> >>                 check.errorf(e.Key.Pos(), "invalid map key type
>>> %s", typ.key)
>>> >>> >>             }
>>> >>> >>         })
>>> >>> >> // Comparable reports whether values of type T are comparable.
>>> >>> >> func Comparable(T Type) bool {
>>> >>> >>     switch t := T.Underlying().(type) {
>>> >>> >>     case *Basic:
>>> >>> >>         // assume invalid types to be comparable
>>> >>> >>         // to avoid follow-up errors
>>> >>> >>         return t.kind != UntypedNil
>>> >>> >>     case *Pointer, *Interface, *Chan:
>>> >>> >>         return true
>>> >>> >>     case *Struct:
>>> >>> >>         for _, f := range t.fields {
>>> >>> >>             if !Comparable(f.typ) {
>>> >>> >>                 return false
>>> >>> >>             }
>>> >>> >>         }
>>> >>> >>         return true
>>> >>> >>     case *Array:
>>> >>> >>         return Comparable(t.elem)
>>> >>> >>     }
>>> >>> >>     return false
>>> >>> >> }
>>> >>> >
>>> >>> > --
>>> >>> > 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...@googlegroups.com.
>>> >>> > For more options, visit https://groups.google.com/d/optout.
>>> >
>>> > --
>>> > 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...@googlegroups.com.
>>> > For more options, visit https://groups.google.com/d/optout.
>>>
>> --
> You received this message because you are subscribed to a topic in the
> Google Groups "golang-nuts" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/golang-nuts/Z0XQueZFoVw/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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.

Reply via email to