Dynamically generate typespecs from module attribute list

This is a great snippet! Here’s a function form of this:

defmodule TypeUtils do
  # https://forum.elixirforum.com/t/dynamically-generate-typespecs-from-module-attribute-list/7078/5
  def list_to_typespec(list) when is_list(list) do
    Enum.reduce(list, &{:|, [], [&1, &2]})
  end
end

Usage example:

  @statuses [:not_started, :completed]
  @type status :: unquote(TypeUtils.list_to_typespec(@statuses))