Protocols enable polymorphism in Elixir. Define protocols with
Implement a protocol with
Instead of sharing protocol implementation with maps, structs require their own protocol implementation.
With the above implementations, we can do:
Protocols let you dispatch to any data type, so long as it implements the protocol. This includes some built-in types such as
Tuples, and others.
Poison allows developers to implement
Encoders for their own structs for serializing them to JSON, by implementing the