Considere el código:Erlang: refactorización sencilla
f(command1, UserId) ->
case is_registered(UserId) of
true ->
%% do command1
ok;
false ->
not_registered
end;
f(command2, UserId) ->
case is_registered(UserId) of
true ->
%% do command2
ok;
false ->
not_registered
end.
is_registered(UserId) ->
%% some checks
Ahora imagina que hay una gran cantidad de comandos y todos ellos son llamadas is_registered al principio. ¿Hay alguna manera de generalizar este comportamiento (refactorizar este código)? Quiero decir que no es una buena idea colocar la misma caja en todos los comandos.