3 ms·
I think the last Erlang example should be simplified further. It uses two different values of Resp to signal an error ("Error" and "{timestamp, Start, Error}"),
by vog 15y ago
I think the last Erlang example should be simplified further. It uses two different values of Resp to signal an error ("Error" and "{timestamp, Start, Error}"), which can be unified for more clarity:
do_some_file_thing(File) ->
Resp = case file:open(File, [raw, binary, read]) of
{ok, Fd} ->
{timestamp, now(), process_file_data(Fd)};
Error ->
{timestamp, now(), Error}
end,
case Resp of
{timestamp, Start, {ok, Processed}} ->
{ok, Start, now(), Processed};
{timestamp, Start, Error} ->
Error
end.