Bracketology.Constants (Grilla Bracketology v0.2.0) View Source
A single module to house hardcoded constants
Typespecs trick - define single source of truth
This trick is used in the specs
@my_types [:only, :atoms, :work, :here]
@type my_type :: unquote(Enum.reduce(@my_types, &{:|, [], [&1, &2]}))
@spec my_types() :: [my_type()]
def my_types, do: @my_types
A module attribute @my_types
is defined. It is a list of atoms.
A type
called my_type
is defined for use in specs.
The allowed values for a my_type
value is the same as the list of atoms.
The list is accessible via the &my_types/1
function, so other modules can
know the allowed values of "my type".
The reason for this is to have a single source of truth.
You can learn more about typespecs here: https://elixir-lang.org/getting-started/typespecs-and-behaviours.html
Link to this section Summary
Link to this section Types
Specs
competition_type() :: :match | :stage | :tournament
Specs
stage_type() :: :battle_royale | :swiss | :round_robin | :double_elimination | :single_elimination
Link to this section Functions
Specs
competition_types() :: [competition_type()]
Specs
stage_types() :: [stage_type()]