Why not make the map an index into a slice of Animal if you're already going for immutability? Simpler/faster to iterate.
type AnimalMap struct {
index map[string]int
items []Animal
}
(The key lookup would become am.items[am.index["value"]])
If you were going for mutability, it'd be simpler to make the index map[string]*Animal (which might not be a bad idea even with immutable access – of course the index matters more/less depending on how much you'd be inserting/deleting.).
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Why not make the
map
an index into a slice ofAnimal
if you're already going for immutability? Simpler/faster to iterate.(The key lookup would become
am.items[am.index["value"]]
)If you were going for mutability, it'd be simpler to make the index
map[string]*Animal
(which might not be a bad idea even with immutable access – of course the index matters more/less depending on how much you'd be inserting/deleting.).