Quantcast
Channel: Replace an element at an index in a list in Erlang - Stack Overflow
Viewing all articles
Browse latest Browse all 2

Replace an element at an index in a list in Erlang

$
0
0

I have a list that will need its elements updated periodically. The elements do not have a key for lists:keyreplace. It will also grow dynamically. Is this a good way to update an element at a specific index in a list? Is there a better algorithm?

List = [1,2,3,4],Index = 3,NewElement = 5,{HeadList, [_|TailList]} = lists:split(Index-1, List),[1,2,5,4] = lists:append([HeadList, [NewElement|TailList]]).

Viewing all articles
Browse latest Browse all 2

Trending Articles