lists:keymerge/3

Jay Nelson <>
Tue Nov 2 17:43:01 CET 2004


Try the following (it's the best I could think of offhand, but it hasn't 
been tested):

listreplace([], Result) -> Result;
listreplace([{Key, Value} = Tuple | More] , List2) ->
  Newlist = lists:keyreplace(Key, 1, List2, Tuple),
  listreplace(More, Newlist).

You'll want to do lists:keysort(1,List2) before sending it in to 
listreplace.


I subscribe to Bjorn's approach of ordering the variable names.  The 
most important point is the pattern of the tuple, I label it as an 
afterthought because I found after I started writing the function that I 
needed a handle for the whole term.

It is a matter of style (or conformity, depending on your co-conspirators).

jay




More information about the erlang-questions mailing list