Agent
defmodule Counter do
use Agent
def start_link(initial_value) do
Agent.start_link(fn -> initial_value end, name: __MODULE__)
end
def value do
#gets agent state, applies ft, then returns
Agent.get(__MODULE__, & &1)
end
def increment do
#applies ft to the state and updates it
Agent.update(__MODULE__, &(&1 + 1))
end
endConsiderations
Raw
Last updated