Finding unique elements of a list

Dominic Williams <>
Wed Dec 1 22:40:53 CET 2004


FWIW, the version I have in my own lib is:

unique(List) ->
     lists:reverse(
       lists:foldl(
         fun(X,Acc) ->
                 accumulate_unless(lists:member(X,Acc),X,Acc)
         end,
         [],
         List)).

accumulate_unless(true, _X, Acc) ->
     Acc;
accumulate_unless(false, X, Acc) ->
     [X|Acc].


Regards,

Dominic Williams
http://www.dominicwilliams.net

----



More information about the erlang-questions mailing list