erlang小函数
assq(Key, List) ->
case lists:keysearch(Key, 1, List) of
{value, {Key, Val}} -> {value, Val};
_ -> false
end.
get_option(Key, Options) ->
case lists:keysearch(Key, 1, Options) of
{value, {_Key, Value}} ->
Value;
_ ->
throw({error, {not_found, Key}})
end.
get_option(Key, Options, Default) ->
case lists:keysearch(Key, 1, Options) of
{value, {_Key, Value}} ->
Value;
_ ->
Default
end.
set_option(Key, Val, Opts) ->
keyreplaceadd(Key, 1, Opts, {Key, Val}).
keyreplaceadd(Key, Pos, List, New) ->
case lists:keysearch(Key, Pos, List) of
{value, _} -> lists:keyreplace(Key, Pos, List, New);
_ -> [New | List]
end.
莫愁前路无知己,天下无人不识君。