English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Tuples (Tuple) in Erlang

Tuples are a composite data type with a fixed number of items. Each item in a tuple is called an element. The number of elements is the size of the tuple.

The following program shows an example of how to use the Tuple data type.

Here, we define aTuple Pwith3items.tuple_sizeA built-in function defined in Erlang can be used to determine the size of a tuple.

Online Example

-module(helloworld). 
-export([start/0}). 
start(). ->
   P = {john,24{june,25}} , 
   io:fwrite("~w",[tuple_size(P)]).

The output of the above program is as follows.

3

Let's look at more operations available for tuples.

Serial NumberMethod and Description
1

is_tuple

This method is used to determine whether the provided item is indeed a tuple.

2

list_to_tuple

This method converts a list to a tuple.

3

tuple_to_list

This method converts a tuple to a list.