當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


erlang merge用法及代碼示例

Erlang merge函數/方法的用法及代碼示例。


此方法用於合並2張Map。

用法


merge(map1,map2)

參數

  • map1−這是第一張需要合並的Map。

  • map2−這是第二張Map,需要與第一張Map合並。

返回值

一個Map,它是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 merge。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。