Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Concat two maps in Elixir

Tags:

maps

elixir

I have two maps in Elixir:

mapA = %{"test1" => "result1"}
mapB = %{"test2" => "result2"}

I want my output to look like this:

[%{"test1" => "result1"}, %{"test2" => "result2"}]
like image 912
nitinjain110588 Avatar asked Oct 29 '25 14:10

nitinjain110588


1 Answers

If you just want to put them in a list, like your example:

[mapA, mapB]
[%{"test1" => "result1"}, %{"test2" => "result2"}]

If what you actually meant is that you wanted to merge the maps:

Map.merge(mapA, mapB)
%{"test1" => "result1", "test2" => "result2"}
like image 154
Adam Millerchip Avatar answered Oct 31 '25 11:10

Adam Millerchip



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!