Erlang – merge

Erlang merge

In this guide, we will discuss Erlang merge. This method is used to merge 2 maps.

Syntax

merge(map1,map2)

Parameters

  • map1 − This is first map which needs to be merged.
  • map2 − This is second map which needs to be merged with the first.

Return Value

A map which is the merge of map1 and map2.

For example

-module(helloworld). 
-export([start/0]). 

start() ->
   Lst1 = [{"a",1},{"b",2},{"c",3}], 
   Lst2 = [{"d",4},{"e",5},{"f",6}], 
   
   Map1 = maps:from_list(Lst1), 
   Map2 = maps:from_list(Lst2), 
   io:fwrite("~p~n",[maps:merge(Map1,Map2)]).

Output

The output of the above program is as follows.

#{"a" => 1,"b" => 2,"c" => 3,"d" => 4,"e" => 5,"f" => 6}

Next Topic : Click Here

This Post Has 2 Comments

Leave a Reply