Erlang - Lists
The List is a structure used to store a collection of data items. In Erlang, Lists are created by enclosing the values in square brackets.
Following is a simple example of creating a list of numbers in Erlang.
-module(helloworld). -export([start/0]). start() -> Lst1 = [1,2,3], io:fwrite("~w~n",[Lst1]).
The output of the above example will be −
[1 2 3]
Let us now discuss the various methods available for Lists. Note that the lists library needs to be imported for these methods to work.
|S.No||Method and Description|
Returns true if Pred(Elem) returns true for all elements Elem in List, otherwise false.
Returns true if Pred(Elem) returns true for at least one element Elem in List.
Returns a new list List3 which is made from the elements of List1 followed by the elements of List2.
Deletes an element from the list and returns a new list.
Drops the last element of a List.
Returns a list which contains N copies of the term Elem
Returns the last element of the list
Returns the element of the list which has the maximum value.
Checks if an element is present in the list or not.
Returns the element of the list which has the minimum value.
Returns the sorted list formed by merging all the sub-lists of ListOfLists.
Returns the Nth element of List.
Returns the Nth tail of the List.
Reverses a list of elements.
Sorts a list of elements.
Returns a sublist of elements.
Returns the sum of elements in the list.