关于文档的proplists:lookup_all
其他方式:
Returns the list of all entries associated with Key in List.
因此,您只能通过键查找:
(kilter@127.0.0.1)1> Db = [{james,london},{fredrik,berlin},{fred,berlin}].
[{james,london},{fredrik,berlin},{fred,berlin}]
(kilter@127.0.0.1)2> proplists:lookup_all(berlin, Db).
[]
(kilter@127.0.0.1)3> proplists:lookup_all(fredrik, Db).
[{fredrik,berlin}]
您可以使用lists:filter
andlists:map
代替:
(kilter@127.0.0.1)7> lists:filter(fun ({K, V}) -> V =:= berlin end, Db).
[{fredrik,berlin},{fred,berlin}]
(kilter@127.0.0.1)8> lists:map(fun ({K,V}) -> K end, lists:filter(fun ({K, V}) -> V =:= berlin end, Db)).
[fredrik,fred]
所以,最后
match(Element, Db) -> lists:map(
fun ({K,V}) -> K end,
lists:filter(fun ({K, V}) -> V =:= Element end, Db)
).