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

@@ -2,9 +2,9 @@ defmodule Tracker do
alias __MODULE__
defstruct total: 0,
koans: MapSet.new(),
visited_modules: MapSet.new(),
on_complete: :noop
koans: MapSet.new(),
visited_modules: MapSet.new(),
on_complete: :noop
def start_link do
Agent.start_link(fn -> %Tracker{} end, name: __MODULE__)
@@ -15,15 +15,17 @@ defmodule Tracker do
end
def set_total(modules) do
total = modules
|> Enum.flat_map(&(&1.all_koans))
|> Enum.count
total =
modules
|> Enum.flat_map(& &1.all_koans)
|> Enum.count()
Agent.update(__MODULE__, fn _ -> %Tracker{total: total} end)
end
def completed(module, koan) do
Agent.update(__MODULE__, &mark_koan_completed(&1, module, koan))
if complete?() do
Agent.cast(__MODULE__, fn state ->
send(state.on_complete, {self(), :complete})
@@ -34,14 +36,18 @@ defmodule Tracker do
def wait_until_complete() do
pid = Process.whereis(Tracker)
receive do
{^pid, :complete} -> :ok
end
end
defp mark_koan_completed(state, module, koan) do
%{state | koans: MapSet.put(state.koans, koan),
visited_modules: MapSet.put(state.visited_modules, module)}
%{
state
| koans: MapSet.put(state.koans, koan),
visited_modules: MapSet.put(state.visited_modules, module)
}
end
def visited do
@@ -54,7 +60,7 @@ defmodule Tracker do
end
def summarize do
state = Agent.get(__MODULE__, &(&1))
state = Agent.get(__MODULE__, & &1)
%{
total: state.total,