This module contains functions for tuple processing.
Note: This is the ALT-specific module, there isn't in upstream Erlang/OTP (yet?).
Unless otherwise stated, all functions assume that position numbering starts at 1. That is, the first element of a list is at position 1.
Whenever an ordering function F is expected as argument, it is assumed that the following properties hold of F for all x, y and z:
append(Tuple1, Tuple2) -> Tuple3
Types:
Tuple1 = Tuple2 = Tuple3 = tuple()
Returns a new tuple Tuple3 which is a concatenation of the elements of Tuple1 and Tuple2.
Semantically equivalent to list_to_tuple(tuple_to_list(Tuple1)++tuple_to_list(Tuple2)), but much faster.
> tuples:append({one, two, three}, {next, more}). {one,two,three,next,more}
append_element(Tuple1, Term) -> Tuple2
Types:
Tuple1 = Tuple2 = tuple()
Term = term()
Returns a new tuple which has one element more than Tuple1, and contains the elements in Tuple1 followed by Term as the last element.
Full equivalent to erlang:append_element(Tuple1, Term).
Semantically equivalent to list_to_tuple(tuple_to_list(Tuple++[Term]) or tuples:from_list(tuples:to_list(Tuple++[Term]), but much faster.
> tuples:append_element({one, two}, three). {one,two,three}
delete(Index, Tuple1) -> Tuple2
Types:
Index = 1..tuple_size(Tuple1)
Tuple1 = Tuple2 = tuple()
Returns a tuple which is a copy of the argument Tuple1, without the element given by the integer argument Index (the first element is the element with index 1).
> tuples:delete(2, {one, two, three}). {one,three}
delete(Index, Num, Tuple1) -> Tuple2
Types:
Index = 1..tuple_size(Tuple1)
Num = 1..tuple_size(Tuple1)-Num+1
Tuple1 = Tuple2 = tuple()
Returns a tuple which is a copy of the argument Tuple1 without Num elements starting the element given by the integer argument Index (the first element is the element with index 1).
> tuples:delete(4, 2, {one, two, three, four, five, six, seven}). {one,two,three,six,seven}
Types:
N = 1..tuple_size(Tuple)
Tuple = tuple()
Returns the Nth element (numbering from 1) of Tuple.
Full equivalent to erlang:element(N, Tuple) or element(N, Tuple).
> tuples:element(2, {a, b, c}). b
Types:
DeepTuple = tuple()
Equivalent to erlang:tuple_size(tuples:flatten(DeepTuple)) or tuples:size(tuples:flatten(DeepTuple)) but more efficient.
> tuples:flatsize({one, {next, more}, two, three}). 5
flatten(DeepTuple) -> FlatTuple
Types:
DeepTuple = FlatTuple = tuple()
Returns a flattened version of DeepTuple.
Semantically equivalent to list_to_tuple(lists:flatten(tuple_to_list(Tuple))), but much faster.
> tuples:flatten({one, {next, more}, two, three}). {one,next,more,two,three}
Types:
List = [term()]
Returns a tuple which corresponds to List. List can contain any Erlang terms.
Full equivalent to erlang:list_to_tuple(List) or list_to_tuple(List).
> from_list([share, ['Ericsson_B', 163]]). {share, ['Ericsson_B', 163]}
insert(Index, Tuple1, Term) -> Tuple2
Types:
Index = 1..tuple_size(Tuple1)
Tuple1 = Tuple2 = tuple()
Term = term()
Returns a tuple which is a copy of the argument Tuple1 with the inserted Term as the Nth element given by the integer Index (the first element is the element with index 1).
> tuples:insert(2, {one, two, three}, next). {one,next,two,three}
erlang:insert_element(Index, Tuple1, Tuple2) -> Tuple3
Types:
Index = 1..tuple_size(Tuple1)
Tuple1 = Tuple2 = Tuple3 = tuple()
Returns a tuple which is a copy of the argument Tuple1 with the inserted elements of Tuple2 starting from the Nth position given by the integer argument Index (the first element is the element with index 1).
> tuples:insert_elements(2, {one, two, three}, {next, more}). {one,next,more,two,three}
make(Arity, InitialValue) -> tuple()
Types:
Arity = int()
InitialValue = term()
Returns a new tuple of the given Arity, where all elements are InitialValue.
Full equivalent to erlang:make_tuple(Arity, InitialValue).
> tuples:make(4, []). {[],[],[],[]}
set_element(Index, Tuple1, Value) -> Tuple2
Types:
Index = 1..tuple_size(Tuple1)
Tuple1 = Tuple2 = tuple()
Value = term()
Returns a tuple which is a copy of the argument Tuple1 with the element given by the integer argument Index (the first element is the element with index 1) replaced by the argument Value.
Full equivalent to erlang:setelement(Index, Tuple1, Value) or setelement(Index, Tuple1, Value).
> tuples:set_element(2, {10, green, bottles}, red). {10,red,bottles}
Types:
Tuple = tuple()
Returns an integer which is the number of elements in Tuple.
Full equivalent to erlang:tuple_to_list(Tuple) or tuple_to_list(Tuple).
> tuples:size({morni, mulle, bwange}). 3
Types:
Tuple = tuple()
Returns a list which corresponds to Tuple. Tuple may contain any Erlang terms.
Full equivalent to erlang:tuple_to_list(Tuple) or tuple_to_list(Tuple).
> tuples:to_list({share, {'Ericsson_B', 163}}). [share,{'Ericsson_B',163}]