Created
June 1, 2020 20:24
-
-
Save josefrichter/081784490c4947b2b0a8293a3897545a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Counter do | |
use Agent | |
def start_link(initial_value) do | |
Agent.start_link(fn -> initial_value end, name: __MODULE__) | |
end | |
def value do | |
Agent.get(__MODULE__, & &1) | |
end | |
def increment do | |
Agent.update(__MODULE__, &(&1 + 1)) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment