> Erlang中文手册 > get_bool/2 返回一个布尔键值选项的值

proplists:get_bool/2

返回一个布尔键值选项的值

用法:

get_bool(Key, List) -> boolean()

内部实现:

-spec get_bool(Key, List) -> boolean() when
      Key :: term(),
      List :: [term()].

get_bool(Key, [P | Ps]) ->
    if is_atom(P), P =:= Key ->
	    true;
       tuple_size(P) >= 1, element(1, P) =:= Key ->
	    case P of
		{_, true} ->
		    true;
		_ ->
		    %% Don't continue the search!
		    false
	    end;
       true ->
	    get_bool(Key, Ps)
    end;
get_bool(_Key, []) ->
    false.

返回一个布尔键值选项的值。如果 proplists:lookup(Key, List) 返回 {Key, true},那么这个函数返回 true,否则返回 false。

proplists:get_bool(k1, [{k1, 1}, {k2, 2}, k1, {k3, 3}, {k4, [[4]]}]).
proplists:get_bool(k3, [{k1, 1}, {k2, 2}, k3, {k3, 3}, {k4, [[4]]}]).
proplists:get_bool(k5, [{k1, 1}, {k2, 2}, k3, {k3, 3}, {k4, [[4]]}]).