Skip to content

Commit

Permalink
fix: bad format
Browse files Browse the repository at this point in the history
  • Loading branch information
yagogarea committed Jun 19, 2024
1 parent 31a14ce commit e0a889c
Showing 1 changed file with 9 additions and 17 deletions.
26 changes: 9 additions & 17 deletions apps/06-almacenamiento-clave-valor/src/db.erl
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@ new() ->
%% @spec write(Key :: integer, Element :: term(), DbRef :: term()) -> term()
%% @end
%%--------------------------------------------------------------------
write(Key, Element, DbRef) when is_list(DbRef) ->
[{Key, Element} | DbRef];
write(_, _, _) ->
erlang:throw("error").
write(Key, Element, DbRef) when is_list(DbRef) andalso is_integer(Key) ->
[{Key, Element} | DbRef].

%%--------------------------------------------------------------------
%% @doc Delete function.
Expand All @@ -28,12 +26,10 @@ write(_, _, _) ->
%%--------------------------------------------------------------------
delete(_, []) ->
[];
delete(Key, [{Key, _} | T]) ->
delete(Key, [{Key, _} | T]) when is_integer(Key) ->
T;
delete(Key, [{X, Y} | T]) ->
[{X, Y}| delete(Key, T)];
delete(_Key, _DbRef) ->
erlang:throw("error").
delete(Key, [{X, Y} | T]) when is_integer(Key) ->
[{X, Y}| delete(Key, T)].

%%--------------------------------------------------------------------
%% @doc Read function.
Expand All @@ -43,9 +39,9 @@ delete(_Key, _DbRef) ->
%%--------------------------------------------------------------------
read(_, []) ->
{error, instance};
read(Key, [{Key, Element} | _]) ->
read(Key, [{Key, Element} | _]) when is_integer(Key) ->
{ok, Element};
read(Key, [_ | T]) ->
read(Key, [_ | T]) when is_integer(Key) ->
read(Key, T).

%%--------------------------------------------------------------------
Expand All @@ -54,16 +50,12 @@ read(Key, [_ | T]) ->
%% @end
%%--------------------------------------------------------------------
match(Element, DbRef) when is_list(DbRef) ->
[X || {X, E} <- DbRef, E =:= Element];
match(_Key, _DbRef) ->
erlang:throw("error").
[X || {X, E} <- DbRef, E =:= Element].

%%--------------------------------------------------------------------
%% @doc Destroy function.
%% @spec destroy(DbRef :: term()) -> ok
%% @end
%%--------------------------------------------------------------------
destroy(DbRef) when is_list(DbRef)->
[];
destroy(_DbRef) ->
erlang:throw("error").
ok.

0 comments on commit e0a889c

Please sign in to comment.