Erlang - 合併



此方法用於合併兩個對映。

語法

merge(map1,map2)

引數

  • map1 − 這是需要合併的第一個對映。

  • map2 − 這是需要與第一個合併的第二個對映。

返回值

一個對映,它是 map1 和 map2 的合併結果。

例如

-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)]).

輸出

以上程式的輸出如下所示。

#{"a" => 1,"b" => 2,"c" => 3,"d" => 4,"e" => 5,"f" => 6}
erlang_maps.htm
廣告

© . All rights reserved.