有人能给我一个例子,说明orddict:map()在Erlang中是如何使用的?
答案 0 :(得分:4)
orddict:map(F,D)将函数F应用于orddict的所有键/值并返回包含key / newvalue的新orddict
1> D = orddict:new().
[]
2> D1 = orddict:store(1,"test",D).
[{1,"test"}]
3> D2 = orddict:store(2,"test",D1).
[{1,"test"},{2,"test"}]
4> D3 = orddict:store(3,"test",D2).
[{1,"test"},{2,"test"},{3,"test"}]
5> orddict:map(fun(K,V) -> V ++ " " ++ integer_to_list(K) end, D3).
[{1,"test 1"},{2,"test 2"},{3,"test 3"}]
6>