Hacker News new | ask | show | jobs
by nemetroid 2187 days ago
> For my design, I decided to enforce that both key and value types are comparable, so I could build a simple demo using two hashtables as an index and reverse index with flipped key/value types.

Surely the demo works equally well without this extra constraint? If the demo had a generic function for creating a reversible mapping it would have been necessary, but as it stands, this extra constraint comes across as avoiding having to write the less aesthetically pleasing

  type Table(type K comparable, V interface{}) struct {
    ...
1 comments

Yep that is true. I wanted both values to be comparable for an easy demo but would write it as you've suggested if I intended to make this a general purpose package.
What I mean is that as written, the demo doesn't need V to be comparable.
Oh wow, for some reason I totally zoned out and finally understand what you mean. Yes, you're right! I should fix that.