以前从未处理过 dict 模块的相对新手,但这似乎对我有用:
dict:fold(fun(Key, Value, Accum) ->
[Value | Accum] end, [], D).
例子:
init() ->
Dict = dict:new(),
Dict2 = dict:append(key, value, Dict),
Dict3 = dict:append(key2, value2, Dict2),
dict:append(key3, value3, Dict3).
grab_values(D) ->
dict:fold(fun(Key, Value, Accum) ->
[Value | Accum] end, [], D).
调用:
4> D = dictfold:init().
{dict,3,16,16,8,80,48,
{[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[]},
{{[],[],
[[key2,value2]],
[[key3,value3]],
[],[],[],[],[],
[[key,value]],
[],[],[],[],[],[]}}}
5> dictfold:grab_values(D).
[[value2],[value3],[value]]