{"action":"created","issue":{"url":"https://api.github.com/repos/golang/go/issues/23905","repository_url":"https://api.github.com/repos/golang/go","labels_url":"https://api.github.com/repos/golang/go/issues/23905/labels{/name}","comments_url":"https://api.github.com/repos/golang/go/issues/23905/comments","events_url":"https://api.github.com/repos/golang/go/issues/23905/events","html_url":"https://github.com/golang/go/issues/23905","id":298071463,"number":23905,"title":"Proposal: add a \"merge\" built-in function to join several slices.","user":{"login":"dotaheor","id":25079101,"avatar_url":"https://avatars3.githubusercontent.com/u/25079101?v=4","gravatar_id":"","url":"https://api.github.com/users/dotaheor","html_url":"https://github.com/dotaheor","followers_url":"https://api.github.com/users/dotaheor/followers","following_url":"https://api.github.com/users/dotaheor/following{/other_user}","gists_url":"https://api.github.com/users/dotaheor/gists{/gist_id}","starred_url":"https://api.github.com/users/dotaheor/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dotaheor/subscriptions","organizations_url":"https://api.github.com/users/dotaheor/orgs","repos_url":"https://api.github.com/users/dotaheor/repos","events_url":"https://api.github.com/users/dotaheor/events{/privacy}","received_events_url":"https://api.github.com/users/dotaheor/received_events","type":"User","site_admin":false},"labels":[{"id":150880249,"url":"https://api.github.com/repos/golang/go/labels/Go2","name":"Go2","color":"ffaaaa","default":false},{"id":150880200,"url":"https://api.github.com/repos/golang/go/labels/LanguageChange","name":"LanguageChange","color":"ffaaaa","default":false},{"id":236419512,"url":"https://api.github.com/repos/golang/go/labels/Proposal","name":"Proposal","color":"ededed","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":{"url":"https://api.github.com/repos/golang/go/milestones/30","html_url":"https://github.com/golang/go/milestone/30","labels_url":"https://api.github.com/repos/golang/go/milestones/30/labels","id":1373555,"number":30,"title":"Proposal","description":"Proposals that are pending (not yet accepted/rejected).\r\n","creator":{"login":"rsc","id":104030,"avatar_url":"https://avatars1.githubusercontent.com/u/104030?v=4","gravatar_id":"","url":"https://api.github.com/users/rsc","html_url":"https://github.com/rsc","followers_url":"https://api.github.com/users/rsc/followers","following_url":"https://api.github.com/users/rsc/following{/other_user}","gists_url":"https://api.github.com/users/rsc/gists{/gist_id}","starred_url":"https://api.github.com/users/rsc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rsc/subscriptions","organizations_url":"https://api.github.com/users/rsc/orgs","repos_url":"https://api.github.com/users/rsc/repos","events_url":"https://api.github.com/users/rsc/events{/privacy}","received_events_url":"https://api.github.com/users/rsc/received_events","type":"User","site_admin":false},"open_issues":224,"closed_issues":380,"state":"open","created_at":"2015-10-24T01:40:49Z","updated_at":"2018-02-28T16:20:53Z","due_on":null,"closed_at":null},"comments":12,"created_at":"2018-02-18T09:36:18Z","updated_at":"2018-03-01T14:44:44Z","closed_at":null,"author_association":"NONE","body":"### The problem\r\n\r\nSometime, we need to insert a slice (call it x) into another (call it y) at the index i of y.\r\nIf the capacity of y is large enough to accept all elements of x, then things would simple.\r\n```\r\nfunc insert1(y, x []T, i int) []T {\r\n\ts := y[:len(s)+len(x)]\r\n\tcopy(s[i+len(x):], s[i:])\r\n\tcopy(s[i:], x)\r\n\treturn s\r\n}\r\n```\r\nHowever, the capacity of y is not large enough to accept all elements of x,\r\nwe must use make to allocate a new slice which is large enough to accept all elements of x and y.\r\n```\r\nfunc insert2(y, x []T, i int) []T {\r\n\ts := make([]T, 0, len(x)+len(y))\r\n\ts = append(s, y[:i]...)\r\n\ts = append(s, x...)\r\n\ts = append(s, y[i:]...)\r\n\treturn s\r\n}\r\n```\r\nThe problem here is that the make function will clear all allocated bytes,\r\nwhich is not essential for this case.\r\n\r\n### The proposal\r\n\r\nSo I propose a merge (or join, or concat) built-in function to merge several slices.\r\n```\r\nmerge(slices ...[][]T) []T\r\n```\r\nso that we can call\r\n```\r\nmerge(y[:i], elements, y[i:])\r\n```\r\nwhich will be more efficient than the insert2 function.\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/golang/go/issues/comments/369613656","html_url":"https://github.com/golang/go/issues/23905#issuecomment-369613656","issue_url":"https://api.github.com/repos/golang/go/issues/23905","id":369613656,"user":{"login":"dotaheor","id":25079101,"avatar_url":"https://avatars3.githubusercontent.com/u/25079101?v=4","gravatar_id":"","url":"https://api.github.com/users/dotaheor","html_url":"https://github.com/dotaheor","followers_url":"https://api.github.com/users/dotaheor/followers","following_url":"https://api.github.com/users/dotaheor/following{/other_user}","gists_url":"https://api.github.com/users/dotaheor/gists{/gist_id}","starred_url":"https://api.github.com/users/dotaheor/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dotaheor/subscriptions","organizations_url":"https://api.github.com/users/dotaheor/orgs","repos_url":"https://api.github.com/users/dotaheor/repos","events_url":"https://api.github.com/users/dotaheor/events{/privacy}","received_events_url":"https://api.github.com/users/dotaheor/received_events","type":"User","site_admin":false},"created_at":"2018-03-01T14:44:44Z","updated_at":"2018-03-01T14:44:44Z","author_association":"NONE","body":"@andlabs `grow` still needs to zero new elements, which is unnecessary."}}
{"actor":{"display_login":"dotaheor"}}