What Are Elixir Tuples And When To Use Them — Tentamen Software Testing Blog

Karlo Smid
1 min readJul 27, 2020

--

TL;DR

In the previous post, we discussed Elixir’s short circuit operators and how those could help you to write less code. Today we explain what Elixir Tuples are and when to use them. This post is part of the functional language series, and it is based on the remarkable book Elixir In Action by Sasa Juric.

Tuple Syntax

In the image above you can see how we defined test_case Tuple. Tuple can have more than two elements. You get Tuple values using Kernel.elem function, and update it using. Kernel.put_elemAs Elixir is immutable, test_case is not changed, but a new variable is created in memory.

When To Use Tuples

We use tuples when we need to return from function simple data type. For example, to indicate that function returned an error with an error message.

Remember

  • What is Tuple syntax
  • How to get Tuple value
  • How to set Tuple value
  • When to use Tuples

Originally published at https://blog.tentamen.eu on July 27, 2020.

--

--

Karlo Smid
Karlo Smid

Written by Karlo Smid

Founder of Tentamen, software testing agency.

No responses yet