Skip to content

Instantly share code, notes, and snippets.

@KronicDeth
Created June 3, 2016 14:37
Show Gist options
  • Save KronicDeth/f99e11892c3aa6e370df746d97f6de92 to your computer and use it in GitHub Desktop.
Save KronicDeth/f99e11892c3aa6e370df746d97f6de92 to your computer and use it in GitHub Desktop.
Destroy DAG for referencing tables until first error
@doc """
Destroys the Directed Acyclic Graph (DAG) of each module in `modules` in order as long as the previous module's
`destroy_dag(destroyed_set, context)` returned `{:ok, new_destroyed_set}`; otherwise, returns the first error.
"""
@spec destroy_dags(destroyed_set, context, modules :: [module, ...]) :: {:ok, destroyed_set} | __MODULE__.Generic.error
def destroy_dags(destroyed_set, context, modules) do
Enum.reduce_while modules, {:ok, destroyed_set}, fn {:ok, acc_destroyed_set}, referencing_module ->
case referencing_module.destroy_dag(destroyed_set, context) do
acc = {:ok, _} ->
{:cont, acc}
acc ->
{:halt, acc}
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment