Skip to content

Support for Sequence and Node as a Node key in Go map #59

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

garysferrao
Copy link

Go does not support slices or maps as a map key.
But we can use fixed length arrays as map keys.

Go does not support slices or maps as a map key.
But we can use fixed length arrays as map keys.
Comment on lines +1042 to +1047
if v.IsNil() {
// Zero value for interface{}
return reflect.Zero(reflect.TypeOf((*interface{})(nil)).Elem()), nil
} else {
return makeComparableKey(v.Elem())
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if v.IsNil() {
// Zero value for interface{}
return reflect.Zero(reflect.TypeOf((*interface{})(nil)).Elem()), nil
} else {
return makeComparableKey(v.Elem())
}
if v.IsNil() {
// Zero value for interface{}
return reflect.Zero(reflect.TypeOf((*interface{})(nil)).Elem()), nil
}
return makeComparableKey(v.Elem())

// type Entry struct { Key K; Value V } with K and V the original map’s key and value types.
//
// - Otherwise, it returns v unchanged (for primitives, structs, etc.).
func makeComparableKey(v reflect.Value) (reflect.Value, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I read the code multiple times, and I feel like err is always nil. The code is recursive, but nothing return an error.

I might be wrong, but removing error from the signature if we don't need it would make the code way simpler

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants