Protocols
August 22, 2023 1 minutes • 78 words
Protocols add polymorphic dispatch to Elixir. They are contracts implementable by data types.
The standard protocols are:
Protocol | Description |
---|---|
Collectable | collects data into a data type |
Enumerable | handles collections in Elixir, as Enum module for eager functions and Stream module for lazy functions |
Inspect | converts data types into their programming language representation |
List.Chars | converts data types to their outside world representation as charlists (non-programming based) |
String.Chars | converts data types to their outside world representation as strings (non-programming based) |