add .formatter.exs + format

This commit is contained in:
Martino Visintin
2018-05-22 21:46:54 +01:00
parent 08c90ce0d8
commit b07df7c780
52 changed files with 332 additions and 264 deletions

View File

@@ -5,36 +5,38 @@ defmodule Agents do
koan "Agents maintain state, so you can ask them about it" do
{:ok, pid} = Agent.start_link(fn -> "Hi there" end)
assert Agent.get(pid, &(&1)) == ___
assert Agent.get(pid, & &1) == ___
end
koan "Agents may also be named so that you don't have to keep the pid around" do
Agent.start_link(fn -> "Why hello" end, name: AgentSmith)
assert Agent.get(AgentSmith, &(&1)) == ___
assert Agent.get(AgentSmith, & &1) == ___
end
koan "Update to update the state" do
Agent.start_link(fn() -> "Hi there" end, name: __MODULE__)
Agent.start_link(fn -> "Hi there" end, name: __MODULE__)
Agent.update(__MODULE__, fn(old) ->
Agent.update(__MODULE__, fn old ->
String.upcase(old)
end)
assert Agent.get(__MODULE__, &(&1)) == ___
assert Agent.get(__MODULE__, & &1) == ___
end
koan "Use get_and_update when you need to read and change a value in one go" do
Agent.start_link(fn() -> ["Milk"] end, name: __MODULE__)
Agent.start_link(fn -> ["Milk"] end, name: __MODULE__)
old_list = Agent.get_and_update(__MODULE__, fn(old) ->
{old, ["Bread" | old]}
end)
old_list =
Agent.get_and_update(__MODULE__, fn old ->
{old, ["Bread" | old]}
end)
assert old_list == ___
assert Agent.get(__MODULE__, &(&1)) == ___
assert Agent.get(__MODULE__, & &1) == ___
end
koan "Somebody has to switch off the light at the end of the day" do
{:ok, pid} = Agent.start_link(fn() -> ["Milk"] end, name: __MODULE__)
{:ok, pid} = Agent.start_link(fn -> ["Milk"] end, name: __MODULE__)
Agent.stop(__MODULE__)