Skip to content
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

Array conversions #24

Merged
merged 3 commits into from Feb 12, 2016
Merged

Conversation

bmatsuo
Copy link
Contributor

@bmatsuo bmatsuo commented Feb 12, 2016

Changes discussed in #3 to achieve efficient map keys. The Array.String() method was added for convenience.

pborman pushed a commit that referenced this pull request Feb 12, 2016
@pborman pborman merged commit cd53251 into pborman:master Feb 12, 2016
// Array returns an array representation of uuid that can be used as a map key.
// Array panics if uuid is not valid.
func (uuid UUID) Array() Array {
if len(uuid) != 16 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why does this panic rather than return an error?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My reasoning was that an error was too cumbersome. When the primary use of this type is to be used as a map key having a single return value is convenient.

m[u.Array()] = record

I figured a panic was better than an zero-values Array because it doesn't mask bugs (getting an array of a nil UUID seems like a bug to me).

Copy link
Contributor

Choose a reason for hiding this comment

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

Makes sense. I agree that a nil UUID would be bad.

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.

None yet

3 participants