Skip to content

Instantly share code, notes, and snippets.

@lorenzosinisi
Last active November 14, 2019 09:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lorenzosinisi/2cdc713348e02413e1801221b6326ad7 to your computer and use it in GitHub Desktop.
Save lorenzosinisi/2cdc713348e02413e1801221b6326ad7 to your computer and use it in GitHub Desktop.
def answer_types do
:code.all_loaded()
# turn everything into a string
|> Enum.map(&(elem(&1, 0) |> to_string))
# take only the modules that are scoped under AnswerType
|> Enum.filter(&Regex.match?(~r/YourModuleName./, &1))
# take the last element from the list (i.e ["ModuleParent", "Child"])
|> Enum.map(&(String.split(&1, ".") |> Enum.take(-1)))
# there may be duplicates
|> Enum.uniq()
# there may be nested lists
|> List.flatten()
end
@talismandev
Copy link

Thank you so much for this function!

@lorenzosinisi
Copy link
Author

welcome @talismandev!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment