FAQ
Have been using map lately. Had a case where I have two maps of the same
signature (key and value types) that I want to merge. The loop was trivial,
but what does append not work for this?

Proposal a=append(a,b) where a and b are maps of identical signature does
the obvious thing. You might think that the assignment of a is redundant,
but a good implementation will append the shorter to the longer and thus
either a or b could be the return value.

My thinking here is that doing it inside the map magic mah be faster than I
can do from outside.

Michael

P.S. Not being lazy. I did this a week ago. Just thinking that if the logic
of copy or append or which ever make sense for maps worked there too, then
the orthogonality would make it seem less complex rather than moreso.

P.P.S If this idea finds a good home, we could also have copy that does
this:

with:
var a []A
b map[B]A

a = append(a, b)

appends the type A elements of b to a
650-335-5765

## Search Discussions

•  at Oct 19, 2012 at 5:17 am ⇧

On Oct 18, 8:46 pm, Michael Jones wrote:
Have been using map lately. Had a case where I have two maps of the same
signature (key and value types) that I want to merge. The loop was trivial,
but what does append not work for this?

Proposal a=append(a,b) where a and b are maps of identical signature does
the obvious thing. You might think that the assignment of a is redundant,
but a good implementation will append the shorter to the longer and thus
either a or b could be the return value.

My thinking here is that doing it inside the map magic mah be faster than I
can do from outside.

What do you expect to happen if two entries have the same keys but
different values? In a loop you have to make an explicit choice or
error out.

-Tarmigan
•  at Oct 19, 2012 at 5:24 am ⇧
You have me there. (blush)
On Thu, Oct 18, 2012 at 10:14 PM, Tarmigan wrote:
On Oct 18, 8:46 pm, Michael Jones wrote:
Have been using map lately. Had a case where I have two maps of the same
signature (key and value types) that I want to merge. The loop was trivial,
but what does append not work for this?

Proposal a=append(a,b) where a and b are maps of identical signature does
the obvious thing. You might think that the assignment of a is redundant,
but a good implementation will append the shorter to the longer and thus
either a or b could be the return value.

My thinking here is that doing it inside the map magic mah be faster than I
can do from outside.

What do you expect to happen if two entries have the same keys but
different values? In a loop you have to make an explicit choice or
error out.

-Tarmigan

--
650-335-5765

## Related Discussions

Discussion Overview
 group golang-dev categories go posted Oct 19, '12 at 3:53a active Oct 19, '12 at 5:24a posts 3 users 2 website golang.org

### 2 users in discussion

Content

People

Support

Translate

site design / logo © 2022 Grokbase