Polymorphism

Sometimes, adopting a new language means letting go of features that you’ve grown to depend on. Even though Elixir decouples the concepts of data, behavior, and time, you still may argue in favor of other OO concepts like polymorphism. For example, in the previous section, we wrote this code:

 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. You might counter “It’s not a bug; it’s a feature.” In some situations, you don’t actually care which object has the function; you only care that it knows how to split("/"). That’s polymorphism.

It’s our position that polymorphism is an essential mechanism for designing applications. You ...

Get Adopting Elixir 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.