Finding unique elements of a list

Carsten Schultz <>
Thu Dec 2 12:22:26 CET 2004

Hi Uffe!

On Wed, Dec 01, 2004 at 06:10:23PM +0100, Ulf Wiger (AL/EAB) wrote:
> Here's another one, shorter, O(1), and, most importantly, 
> cuter 


> (functional purists may retch at will):

I have just learned a new word ;-)

Ok, since you asked for it...

> u2(L) ->
>     T = ets:new(temp,[set]),
>     L1 = lists:filter(fun(X) -> ets:insert_new(T, {X,1}) end, L),
>     ets:delete(T),
>     L1.

The documentation of lists:filter does not say anything about the
order in which the predicate function is called for the various list
elements.  It does not even state if it is called several times if an
element appears several times.

This is nasty.  But nastyness and cuteness go together often enough,
so who cares.

Take care,


Carsten Schultz (2:38, 33:47), FB Mathematik, FU Berlin
PGP/GPG key on the key servers, 
fingerprint on my home page.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <>

More information about the erlang-questions mailing list