proplists:get_value/2
获取一个键值属性列表的值
用法:
get_value(Key, List) -> term()
内部实现:
%% @equiv get_value(Key, List, undefined)
-spec get_value(Key, List) -> term() when
Key :: term(),
List :: [term()].
get_value(Key, List) ->
get_value(Key, List, undefined).
-spec get_value(Key, List, Default) -> term() when
Key :: term(),
List :: [term()],
Default :: term().
get_value(Key, [P | Ps], Default) ->
if is_atom(P), P =:= Key ->
true;
tuple_size(P) >= 1, element(1, P) =:= Key ->
case P of
{_, Value} ->
Value;
_ ->
%% Dont continue the search!
Default
end;
true ->
get_value(Key, Ps, Default)
end;
get_value(_Key, [], Default) ->
Default.
返回一个键值属性列表 List 里跟 Key 关联的值。如果列表存在这个键的值,则返回该值,否则返回 undefined。其效用跟 proplists:get_value(Key, List, undefined) 一样。
proplists:get_value(a, [{a, b}, {c, d}]).
proplists:get_value(e, [{a, b}, {c, d}]).
proplists:get_value(a, [a, b, c, d]).
proplists:get_value(b, [a, b, c, d]).
proplists:get_value(e, [a, b, c, d]).