October 2014
Intermediate to advanced
280 pages
7h 20m
English
Protocol definitions are very similar to basic module definitions. They can contain module- and function-level documentation (@moduledoc and @doc), and they will contain one or more function definitions. However, these functions will not have bodies—they are there simply to declare the interface that the protocol requires.
For example, here is the definition of the Inspect protocol:
| | defprotocol Inspect do |
| | def inspect(thing, opts) |
| | end |
Just like a module, the protocol defines one or more functions. But we implement the code separately.
Read now
Unlock full access