Elixir utility methods for typespecs.
Summary
Functions
Builds a union type from a list of static values.
Types
Functions
Builds a union type from a list of static values.
This is useful for generating typespecs for enums when the values are already
known at compile-time. To use it, you must call this inside a @type
definition inside an unquote(...) expression.
Raises an error for invalid literals.
Examples
# Given a list of static values:
@statuses [:open, :closed]
@priorities [1, 2, 3]
# You can use them in a @type definition:
@type status :: unquote(Typespecs.from_list(@statuses))
@type priority :: unquote(Typespecs.from_list(@priorities)) | nilThe above is equivalent to writing these typespecs by hand:
@type status :: :open | :closed
@type priority :: 1 | 2 | 3 | nil