Using a literal parameter to choose between multiple function heads

Here’s an example of “two heads” with overlapping implementation:

https://github.com/elixir-lang/elixir/blob/7533e56c1baec77c2aa1a4c0ad02730fae464201/lib/elixir/lib/calendar/date.ex#L348-L359

The heads here are matching on an atom (Calendar.ISO) inside the input struct, and the second one depends directly on the first. Making them separate functions would obscure that coupling.

The function called to do the work, Calendar.ISO.date_to_string is another example of this style:

https://github.com/elixir-lang/elixir/blob/7533e56c1baec77c2aa1a4c0ad02730fae464201/lib/elixir/lib/calendar/iso.ex#L899-L911

date_to_string is only responsible for type guards and delegates its work to a helper function. Passing the format as an argument instead of having date_to_string_basic and date_to_string_extended helps here, because the decision about which format to use (in the code calling to_iso8601) is several layers of function calls away from where the code branches (date_to_string_guarded’s two heads).