lists:keysearch/3
在一个元组列表里查找一个元素
用法:
keysearch(Key, N, TupleList) -> {value, Tuple} | false
内部实现:
%% Shadowed by erl_bif_types: lists:keysearch/3
-spec keysearch(Key, N, TupleList) -> {value, Tuple} | false when
Key :: term(),
N :: pos_integer(),
TupleList :: [Tuple],
Tuple :: tuple().
keysearch(_, _, _) ->
erlang:nif_error(undef).
跟 lists:keyfind/3 一样,都是从元组列表 TupleList 里查找元组的第 N 个值跟 Key 是一样的元素,只不过成功匹配找到时,返回值的格式不一样。
TupleList = [{a, 1}, {b, 2}, {c, 3}, {d, 4}],
lists:keysearch(b, 1, TupleList).