If you come from Erlang and are familiar with the GenServer behaviour you may be
interested in the Agent set of methods that ship with Elixir. They provide a
lightweight mechanic to save and retrieve state. Here are two functionally
equivalent modules, one written as a GenServer and the other with Agent.
|
|
Pretty nice how much you can shrink the code; and for things as trivial as this
you probably don’t even need to have a module at all! To be fair I used the
anonymous function version of Agent; which makes it seem a lot smaller. Here
is the same one again with non-anonymous functions.
|