Specifications for Functions and Callbacks

Learn about the specifications of functions using @spec.

We'll cover the following

The @spec attribute specifies a function’s parameter count, types, and return value type. It can appear anywhere in a module that defines the function, but by convention, it sits immediately before the function definition, following any function documentation. We’ve already seen the syntax: @spec function_name( param1_type, ...) :: return_type

Examples

Let’s see some examples. These come from the built-in Dict module.

Get hands-on with 1200+ tech skills courses.