Function return type conventions

I’m looking for any feedback on what the conventions are for returning different types from functions with same name but different arity.

For example if function foo/1 returns a list, is it sensible that foo/2 returns a map. Or should I be looking at a different name for the second function to prevent possible confusion?

1 Like

Hello @swelham !

Usually, it is a better idea for clarity to have a uniform return type across functions with different arity but the same name.
This is simply because it is easier to read.

Syntactically (for the compiler), foo/1 and foo/2 are considered completely separate (one of them might even be private while the other is not, for instance). But conceptually (for us human developers), it makes a lot of sense to only use a single name for a single purpose. This is also why a helper such as h in IEx will return the documentation for all function arities of the function name you enter.


Hi @Qqwy.

That’s what I thought, thanks.