swelham

swelham

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?

Showing Posts 1 to 2

Qqwy

Qqwy

TypeCheck Core Team

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.

swelham

swelham OP

Hi @Qqwy.

That’s what I thought, thanks.

— All posts loaded —

Where Next? Top

Trending in Discussions Top

sntran
In my third year of college, around 2010, I found Erlang. A few years later, I found Elixir. I liked the ideas at once: many small proces...
New
bartblast
This is where the projects in the Hologram Showcase get posted: apps built with Hologram and libraries made for it. New ones go up usuall...
New
karolina.curiosum
Hi everyone! This is our fourth edition. Last year, 1,000+ developers took part. The more of you who answer, the more useful the results...
New
mandar1045
I’ve been fixing race condition / crash bugs in an open source org, for a few months now and almost all of them had the same problem. The...
New
fredwu
Over the years I’ve tried dozens of time tracking and invoicing apps, and Harvest was the only one I liked. Primarily due to its relative...
New
New
budgie
I have a project that I’d like to build in Elixir, but there’s a statistical decision engine component that will likely use hierarchical ...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
261 13183 112
New
mudasobwa
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
OndrejValenta
(I just needed to vent somewhere and LinkedIn is full of hope, or hype, I’m not sure which exactly) AI dream has many faces, but general...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
charlenopires
Hi everyone :waving_hand: I’ve been working on PhiaUI, an open-source UI component library for Phoenix LiveView, and I wanted to share i...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews