Hook tracker into Execute module via hook

This commit is contained in:
Felipe Sere
2016-04-24 13:10:05 +01:00
parent c9ee4dbae0
commit 1625ef7d99
3 changed files with 13 additions and 2 deletions

View File

@@ -1,12 +1,18 @@
defmodule Execute do
def run_module(module) do
def run_module(module, callback \\ fn(result, koan) -> nil end) do
Enum.reduce_while(module.all_koans, :passed, fn(koan, _) ->
module
|> run_koan(koan)
|> hook(koan, callback)
|> continue?
end)
end
defp hook(result,koan, callback) do
callback.(result, koan)
result
end
defp continue?(:passed), do: {:cont, :passed}
defp continue?(result), do: {:halt, result}