Skip to content

Instantly share code, notes, and snippets.

@kipcole9
Last active July 18, 2022 23:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kipcole9/6771533e88d199bc15bcd521021b4274 to your computer and use it in GitHub Desktop.
Save kipcole9/6771533e88d199bc15bcd521021b4274 to your computer and use it in GitHub Desktop.
Create a union type from a list
# Converts a list of atoms into a typespec
type = &Enum.reduce(&1, fn x, acc -> {:|, [], [x, acc]} end)
@grammatical_gender [
:animate,
:inanimate,
:personal,
:common,
:feminine,
:masculine,
:neuter
]
@type grammatical_gender :: unquote(type.(@grammatical_gender))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment