Protocols Are Polymorphism

When you want to write a function that behaves differently depending on the type of its arguments, you’re looking at a polymorphic function. Elixir protocols give you a tidy and controlled way to implement this. Whether you’re integrating your types into the existing Elixir library or creating a new library with a flexible interface, protocols let you package the behaviour in a well-documented and disciplined way. And with that, we’re almost done. But when you write about a language, there are always little details that don’t seem to fit anywhere. That’s why the next chapter is full of odds and ends.

Get Programming Elixir 1.3 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.