I'm trying to learn elixir(but mostly functional programming)
I am implementing a very simple GenServer which basically wraps a list of entries. The maximum count of entries and the maximum size (in bytes) of each param is restricted(config file)
defmodule List do
def init(_) do
{:ok, []}
end
def handle_call({:insert, param1, param2, param3}, from, list) do
import Application
param1_max_size = get_env(:app, ....)
param2_max_size = get_env(:app, ....)
param2_max_size = get_env(:app, ....)
max_items_count = get_env(:app, ....)
## should be {:reply, {:error, :your_list_is_full}, list} if list is full
## should be {:reply, {:error, {:check_this_args_please, wrong_params_list}, list} if any param is wrong. wrong_params_list contains the offending params
## should be {:reply, {:ok}, [{param1, param2, param3} | list ]} otherwise
end
end
I know it seems easy but basically i'm trying to find an elegant functional way to do that. My head is procedural and i always end up in a "nested-if-else-hell" using = operator like if it were the C one.
thx