lists:keymerge/3
Richard A. O'Keefe
ok@REDACTED
Wed Nov 3 02:43:27 CET 2004
Vance Shipley <vances@REDACTED> was surprised that
1> lists:keymerge(1, [{1,foo}], [{1,a},{2,b},{3,c}]).
actually does a _merge_ like its name says and returns
[{1,foo},{1,a},{2,b},{3,c}]
The thing that distinguishes a merge from other operations is that
- unlike append, it requires and returns ordered lists
- unlike union, its result contains ALL the elements of the inputs.
The documentation is really quite clear:
Returns the sorted list formed by merging List1 and List2.
The merge is performed on the Nth element of each tuple.
Both List1 and List2 must be key-sorted prior to evaluating this function;
otherwise the result is undefined (and probably unexpected).
>>>>When elements in the input lists compare equal, elements from List1
>>>>are picked before elements from List2.
In short, it's not a bug.
It would not be hard to write a keyunion/3 function if it proved useful.
More information about the erlang-questions
mailing list