When to Use Maps or Records

Records are just tuples in disguise, so they have the same storage and performance characteristics as tuples. Maps use more storage than tuples and have slower lookup properties. On the other hand, maps are far more flexible than tuples.

Records should be used in the following cases:

  • When you can represent your data using a fixed number of predetermined atoms

  • When the number of elements in the record and the names of the elements will not change with time

  • When storage is an issue, typically when you have a large array of tuples and each tuple has the same structure

Maps are appropriate for the following cases:

  • Representing key-value data structures where the keys are not known in advance

  • Representing data with large ...

Get Programming Erlang, 2nd Edition 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.