In this guide, we will discuss Erlang duplicate. Returns a list which contains N copies of the term Elem.
Syntax
duplicate(N,Elem)
Parameters
- N − The number of times the element needs to be duplicated in the list.
- Elem − The element which needs to be duplicated in the list.
Return Value
Returns a new list with the Element duplicated N times.
For example
-module(helloworld). -import(lists,[duplicate/2]). -export([start/0]). start() -> Lst1 = duplicate(5,1), io:fwrite("~w~n",[Lst1]).
Output
When we run the above program we will get the following result.
[1,1,1,1,1]
Next Topic : Click Here
Pingback: Erlang - droplast | Adglob Infosystem Pvt Ltd
Pingback: Erlang - Lists | Adglob Infosystem Pvt Ltd