100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace
Programming

Lists and Tuples in Elixir

Learn how Elixir's two core sequential data structures — singly linked lists and fixed-size tuples — are represented in memory and when to use each one.

Data & CollectionsBeginner9 min readJul 10, 2026
Analogies

Lists and Tuples in Elixir

Elixir gives you two fundamentally different ways to group values in order: lists and tuples. A list, written as [1, 2, 3], is a singly linked list built out of head/tail pairs called cons cells — each element points to the rest of the list. A tuple, written as {1, 2, 3}, is a fixed-size, contiguous block of memory where every element sits at a known offset. Because they are stored so differently, they behave very differently under the hood: lists are cheap to grow at the front but expensive to index into, while tuples are cheap to read from any position but expensive to change.

🏏

Cricket analogy: A list is like a Test match scorecard built ball by ball — you can always prepend the next delivery to the front of the over, but finding the 47th ball bowled means walking through every entry before it, similar to how MS Dhoni's famous 2011 World Cup final innings can only be replayed delivery by delivery.

Working with Lists

Internally, an Elixir list is either the empty list [] or a cons cell of a head element and a tail that is itself a list, so [1, 2, 3] is really [1 | [2 | [3 | []]]]. This structure makes prepending with the | (cons) operator an O(1) operation, because you're just creating one new cell pointing at the existing list — nothing is copied. Appending to the end, or reading the element at index n, is O(n) because Elixir must walk the entire chain from the head. Functions like Enum.at/2, List.first/1, and hd/1 reflect this: hd/1 and List.first/1 are fast, but Enum.at(list, 500) is not.

🏏

Cricket analogy: Prepending to a list is like a substitute fielder being added to the XI at the last moment before the toss — one quick change at the front — while calling Enum.at on a long list is like having to review every over of a rain-delayed ODI innings just to find what happened at over 40.

Working with Tuples

Tuples store a fixed number of elements in contiguous memory with a size header, so elem(tuple, index) is an O(1) direct-offset read regardless of tuple size. This makes tuples ideal for fixed-shape data that you read often but rarely restructure, such as coordinates {x, y}, RGB colors {255, 0, 0}, or the ubiquitous {:ok, value} and {:error, reason} result tuples returned by functions like File.read/1 or Map.fetch/2. Because the tuple's tag (the first element, usually an atom like :ok or :error) is known at the call site, pattern matching on tuples in a case or function clause is both fast and expressive.

🏏

Cricket analogy: A tuple like {:out, "bowled"} mirrors an umpire's fixed decision format — outcome plus mode of dismissal — always two slots, read instantly the way a third umpire reviews a DRS verdict.

Choosing Between Lists and Tuples

The rule of thumb is: use lists for collections whose length varies and that you mostly traverse from the front (recursion, Enum pipelines, streaming), and use tuples for a fixed, small number of heterogeneous values you access by position, especially return values. Because tuples are contiguous, put_elem/3 or setelem-style updates must copy the entire tuple to produce a new one, so tuples are a poor fit for anything that grows or shrinks, or that you update repeatedly in a loop — that pattern belongs to a list, a map, or an accumulator passed through recursion.

🏏

Cricket analogy: Choosing a tuple for a fixed match result {team, runs, wickets} is right, but tracking every ball of an innings calls for a list, the way Cricinfo's ball-by-ball commentary grows with each delivery rather than being a fixed-size record.

Common List and Tuple Functions

The List module offers List.flatten/1 to collapse nested lists, List.first/1 and List.last/1 for endpoints, and List.delete/2 for removing a value, while the broader Enum module (map, filter, reduce, sort) works on any list because lists implement the Enumerable protocol. The Tuple module is deliberately small: Tuple.to_list/1, Tuple.insert_at/3, Tuple.delete_at/2, and elem/2 cover most needs, reflecting that tuples are meant to stay small and fixed rather than be manipulated like collections.

🏏

Cricket analogy: List.flatten mirrors merging separate innings-by-innings wicket lists from a multi-day Test into one flat fall-of-wickets list for the scorecard.

elixir
# Lists: prepend is O(1), append and indexing are O(n)
list = [1, 2, 3]
new_list = [0 | list]        # [0, 1, 2, 3] - cheap
appended = list ++ [4]       # [1, 2, 3, 4] - copies the left list
List.first(list)             # 1
Enum.at(list, 2)              # 3 - walks the list

# Tuples: fixed size, O(1) positional access
result = {:ok, %{id: 1, name: "Ada"}}

case result do
  {:ok, user} -> IO.puts("Loaded #{user.name}")
  {:error, reason} -> IO.puts("Failed: #{reason}")
end

elem(result, 0)               # :ok
put_elem(result, 0, :updated) # {:updated, %{id: 1, name: "Ada"}} - new tuple, full copy

Avoid growing a tuple inside a loop or repeatedly calling put_elem/3 on a large tuple — each call copies the entire tuple, turning an apparently simple update into an O(n) operation per iteration. If you need a mutable-feeling, appendable structure, reach for a list built with recursion and [head | acc], or a map.

The {:ok, result} / {:error, reason} tuple convention is idiomatic across the Elixir standard library and most community libraries. Pattern matching directly on the tag, as in {:ok, value} <- File.read(path), is the standard way to branch on success versus failure without exceptions.

  • Lists are singly linked chains of head/tail cons cells; prepending is O(1) but indexing is O(n).
  • Tuples are fixed-size, contiguous structures; elem/2 gives O(1) positional access.
  • Use lists for variable-length collections traversed with recursion or Enum.
  • Use tuples for small, fixed-shape data, especially {:ok, value} / {:error, reason} results.
  • put_elem/3 copies the whole tuple, so tuples are a poor fit for repeated updates.
  • The List and Enum modules cover list manipulation; the Tuple module stays intentionally minimal.
  • Pattern matching on tuple tags like :ok and :error is the idiomatic Elixir control-flow style.

Practice what you learned

Was this page helpful?

Topics covered

#Programming#ElixirStudyNotes#ListsAndTuplesInElixir#Lists#Tuples#Elixir#Choosing#DataStructures#StudyNotes#SkillVeris

Frequently Asked Questions

21 categories · pick one to explore

Where can I get free study notes for programming and tech subjects?
SkillVeris offers completely free study notes covering programming and tech subjects, with no signup fees or paywalls. The notes are structured by course and topic, written for quick understanding, and enriched with the Learn Through Hobbies analogy method, so you can revise concepts through cricket, music, gaming, cooking and more.
Are SkillVeris study notes good for exam revision?
Yes, the study notes are designed for efficient revision: each topic answers its heading immediately, keeps explanations concise, and links to related glossary terms and cheat sheets. Students preparing for university exams or certification tests use them as quick revision notes because they distil concepts without the padding of full textbooks.
What subjects do the free study notes cover?
The study notes span the platform's main domains, including AI and machine learning, Python and programming, web development, DevOps, cloud, security and databases. Coverage mirrors the 37 live courses, so notes exist for the topics you are actually studying, and new note sets are added as courses launch.
How are SkillVeris study notes different from regular textbooks?
The notes are answer-first, concise and free, whereas textbooks are long and often expensive. Each section explains one concept directly, then reinforces it through selectable hobby analogies like cricket or cooking. Notes also cross-link to the glossary, blog and cheat sheets, letting you jump to related material instantly instead of flipping pages.
Can I use the developer study material without creating an account?
The study notes are free to access, and SkillVeris does not charge anything for its developer study material at any point. Browsing notes is straightforward from the Study Notes section, and if you want progress tracking, certificates and AI Mentor conversations tied to your learning, a free account unlocks those extras.
Do the study notes explain concepts with analogies?
Yes, this is a signature SkillVeris feature. Study notes use the Learn Through Hobbies method, explaining technical concepts through analogies from twelve domains including cricket, music, gaming, photography, travel, movies, fitness, chess, cooking, finance, business and sports. You can switch the analogy domain instantly to whichever hobby makes the concept click.
Are the revision notes suitable for last-minute exam preparation?
Yes, revision notes on SkillVeris work well for last-minute preparation because every section states the answer in its first sentences, so skimming is genuinely effective. Pair them with the relevant cheat sheet for formulas and syntax, and use the glossary for any unfamiliar term you meet while cramming.
Is there free study material for AI and machine learning?
Yes, SkillVeris provides free study notes across its AI and ML catalogue, covering Python for AI, deep learning frameworks like PyTorch and TensorFlow, Hugging Face Transformers, Large Language Models, RAG, AI agents and MLOps. All of it is free, making it a strong resource for Indian students and global learners alike.
Can beginners understand the study notes, or are they for experts?
Beginners can absolutely use them. The notes are written in plain language, define terms as they appear, and lean on hobby analogies to make abstract ideas concrete. Difficulty scales with the underlying course level, so beginner-course notes stay gentle while advanced-course notes go deeper, and the glossary supports you throughout.
How do study notes connect with SkillVeris courses?
Study notes are organised by course and topic, so they map directly to the structured courses and their 24–40-lesson curriculum. Many learners study a lesson first, then use the matching notes for revision before module assessments and the final exam, where 80 percent is required to pass and earn the certificate.
Are there study notes for Python specifically?
Yes, Python is well covered through notes tied to the Python-focused courses, including Python for AI and ML. Topics span fundamentals through applied machine learning usage. You can reinforce the notes with Python practice in Code Lab, which runs code in your browser with no installation required.
Do the study notes include code examples?
Yes, study notes include code examples wherever a concept is best shown in code, alongside explanations, key points and analogies. Reading a snippet in the notes and then reproducing it yourself in Code Lab is an effective loop, since Code Lab lets you run code in the browser across six languages.
How often is new study material added to SkillVeris?
Study material grows alongside the course catalogue. Whenever new courses join the platform's 37 live courses, matching study notes, glossary entries and cheat sheets are added so the resources stay in sync. Existing notes are also refined over time, so it is worth revisiting topics you studied earlier.
Can I use SkillVeris notes to prepare for technical interviews?
Yes, the notes make excellent interview revision because they compress each concept into direct, answer-first explanations, which mirrors how you should answer interview questions. Combine them with the SkillVeris interview questions feature, which includes readiness scoring, to test whether your revision has actually made you interview-ready.
Are the study notes mobile-friendly for studying on the go?
Yes, the study notes are built to load fast and read comfortably on mobile devices, so you can revise during a commute or between classes. Sections are short and answer-first, which suits small screens, and analogy switching works on mobile too, letting you study anywhere without carrying books.
What is the difference between study notes and cheat sheets?
Study notes explain concepts in depth with context, examples and analogies, making them ideal for learning and revision. Cheat sheets are compact quick-reference summaries of syntax, commands and key facts, ideal once you already understand a topic. Most learners study the notes first, then keep the cheat sheet handy while coding.
Do study notes help if I am stuck on a course lesson?
Yes, reading the matching study notes often clarifies a lesson because the same concept is explained from a different angle, frequently with a different analogy. If you are still stuck, ask the AI Mentor, which answers 24/7 at Quick, Detailed or Deep-dive depth until the idea genuinely makes sense.
Is there free study material for DevOps and cloud topics?
Yes, SkillVeris carries free study notes for DevOps and cloud topics as part of its coverage across 37 live courses. The material suits learners following the DevOps Engineer or Cloud Engineer paths, and it links to related glossary terms and cheat sheets so you can revise the whole toolchain in one place.
Can school or college students in India use these notes for projects?
Yes, students across India and worldwide use SkillVeris notes for coursework, projects and exam preparation, and everything is free, which matters for student budgets. The notes explain concepts clearly enough to cite in project reports, and Code Lab lets you prototype the project code directly in your browser.
How should I combine study notes with other SkillVeris resources?
A proven loop: learn from a course lesson, revise with the matching study notes, look up unfamiliar terms in the glossary, keep the cheat sheet open while practising in Code Lab, and quiz yourself with interview questions. The AI Mentor fills any remaining gaps 24/7, at whatever depth you need.

What Learners Say

Real journeys from the SkillVeris community — swipe for more.

SkillVeris taught me Python through Cricket. Now I’m building real projects and feeling confident!
Arjun S. · B.Tech Student
The best platform for hobby-based learning. Concepts finally stick.
Priya R. · Data Analyst
I went from zero coding to a portfolio of projects — all by learning through my love for gaming. Landed my first internship!
Kabir M. · CS Undergraduate
Trending Topics50 popular tags — tap to explore
Trending CoursesAll 37 free courses — tap to browse