1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

GO言語 複数のマップをマージ する

Last updated at Posted at 2020-07-01

逆引きGolangには2つのマップをマージするやり方が書いてあったが、
今回は2つ以上のマップをマージする可変長引数関数を作ってみた。
これにより、マップを幾つでもマージしてくれる。


func merge(m ...map[string]interface{}) map[string]interface{} {
	ans := make(map[string]interface{}, 0)

	for _, c := range m {
		for k, v := range c {
			ans[k] = v
		}
	}
	return ans
}

参考文献

逆引きGolang (https://ashitani.jp/golangtips/tips_map.html#map_Merge)

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?