Created
June 3, 2016 14:37
-
-
Save KronicDeth/f99e11892c3aa6e370df746d97f6de92 to your computer and use it in GitHub Desktop.
Destroy DAG for referencing tables until first error
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
@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