Polymorphism
Learn about polymorphism and its types in Elixir.
Polymorphism in Elixir
Sometimes, adopting a new language means letting go of features that we’ve grown to depend on. Even though Elixir decouples the concepts of data, behavior, and time, we still may argue in favor of other OO concepts like polymorphism. For example, in the previous lesson, we wrote this code:
Press + to interact
URI.parse(url).path.split("/").last
We argued that .split("/"). last
may be a source of confusion since we don’t know where methods like split
come from. We might counter, “It’s not a bug. It’s a feature.”
In some situations, we don’t actually care which object has the function. We only care that it knows how to split("/")
. That’s ...