Is it possible to build a union type from a list? For example, something like:
defmodule HatEnum do
@variants [:bowler, :sombrero]
# duplicated knowledge.
# declare this based on @variants instead?
@type t :: :bowler | :sombrero
@spec name(t()) :: String.t()
def name(variant) when variant in @variants do
variant
|> to_string()
|> String.capitalize()
end
end