ERLANG List Functions 1
-module(list_functions).
-export([start/1]).
start(List) ->
list_max(List),
list_min(List),
list_sum(List),
list_sort(List),
nth_element_of_the_list(List),
separate_head_and_tail(List),
concat_content_of_the_list(List),
delete_defined_value_from_list(List),
last_element_of_list(List),
is_element_is_a_member(List),
list_split(List)
sub_list(List),
sub_list_start_from_to(List),
sort_and_remove_redundant_values(List),
tail_after_specified_number_of_elements(List),
lists_unique_merge(List).
list_max(List) ->
io:format("Max of list... ~p~n",[lists:max(List)]). % lists:max(name_of_the_list)
list_min(List) ->
io:format("Min of the list... ~p~n",[lists:min(List)]). % lists:max(name_of_the_list)
list_sum(List) ->
io:format("Sum of the list... ~p~n",[lists:sum(List)]). % lists:sum(name_of_the_list)
list_sort(List) ->
io:format("Sorted version of the list... ~p~n",[lists:sort(List)]). % lists:sort(name_of_the_list)
nth_element_of_the_list(List) ->
io:format("2nd element of the list... ~p~n",[lists:nth(2,List)]). % lists:nth(index_no, name_of_the_list)
separate_head_and_tail([Head|Tail]) ->
io:format("Head of the list... ~p~n",[Head]),
io:format("Tail of the list... ~p~n",[Tail]).
concat_content_of_the_list(List) ->
io:format("Concantinated version of the list... ~p ~n",[lists:concat(List)]). % lists:concat(name_of_the_list)
delete_defined_value_from_list(List) ->
io:format("Deletes value first value 4 from the list... ~p ~n",[lists:delete(4,List)]). % lists:delete(index_no,name_of_the_list)
last_element_of_list(List) ->
io:format("List after dropping the last value... ~p ~n",[lists:last(List)]). % lists:last(List)
is_element_is_a_member(List) ->
io:format("Is element 1 is existing... ~p~n",[lists:member(1,List)]). % lists:member(elment_value, name_of_the_list)
list_split(List) ->
io:format("Original list has been split to 2 lists and 1 list contain 4 and 2 list contains rest ...~p ~n",[lists:split(4,List)]). % lists:split(items_to_be_included_into_1_list, name_of_the_list)
sub_list(List) ->
io:format("Sub list is genarated with elements from index 1 to 6.... ~p~n",[lists:sublist(List,6)]). % lists:sublist(name_of_the_original_list, index_no_of_the_last_index_to_be_subset)
sub_list_start_from_to(List) ->
io:format("Sub list is generated from original from a specified start index to specified end index ~p~n",[lists:sublist(List,2,6)]). % lists:sublist(name_of_the_list, start_index,end_index)
sort_and_remove_redundant_values(List) ->
io:format("Original list is sorted with identical values... ~p~n",[lists:usort(List)]). % lists:usort(Name_of_the_list)
tail_after_specified_number_of_elements(List) ->
io:format("Tail after 4 elements is... ~p~n",[lists:nthtail(4,List)]). %lists:nthtail(index_of_the_element_which_is_immediately_before_the_required_tail, name_of_the_list)
lists_unique_merge(List) ->
io:format("Merge list of lists with unique values ~p ~n",[lists:umerge(List)]).
Labels: erlang, examples, List functions

0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home