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.

Comments?

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
Michael T. Jones | Chief Technology Advocate | mtj@google.com | +1
650-335-5765

Search Discussions

  • Tarmigan 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.

    Comments?
    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
  • Michael Jones 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.

    Comments?
    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


    --
    Michael T. Jones | Chief Technology Advocate | mtj@google.com | +1
    650-335-5765

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-dev @
categoriesgo
postedOct 19, '12 at 3:53a
activeOct 19, '12 at 5:24a
posts3
users2
websitegolang.org

2 users in discussion

Michael Jones: 2 posts Tarmigan: 1 post

People

Translate

site design / logo © 2022 Grokbase