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

Image for post
Image for post

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

Written by

Founder of Tentamen, software testing agency.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store