You’ve already given a pretty good summary of the differences, so in any conditions where one of those things is important it should help you decide on which to use.
The way to think about it is that Lists are open-ended data structures and their size can vary at runtime while Tuples have a constant size set at compile time.
For example if you wanted to store all the commands the user has given during an iex
session you would want a list – the length of that list will depend on the number of commands given in that session. Contrast this with a typical use-case for tuples – returning {:ok, result}
or {:error, reason}
from a method – here the number of elements is known up-front and so you don’t pay an unacceptable price for the performance improvements of Tuples.
As for enumeration – Tuples conceptually aren’t collections and every element’s position is supposed to also denote its role. Consider an {:ok, #PID<0.336.0>}
Tuple – iterating over it would first give you an :ok
and then a #PID<0.336.0>
, it would be very strange to write a function acting in a uniform way on those things.