Finding unique elements of a list

James Hague jamesh@REDACTED
Wed Dec 1 17:47:38 CET 2004

Is there a standard Erlang library function or idiom for removing duplicate
items from an unsorted list?  Ideally the elements in the final list should
be in the order they were passed in, except without duplicates:

	[3,5,2,2,3] -> [3,5,2].

If order doesn't matter there are some easy options:

1. lists:usort(L)
2. gb_sets:to_list(gb_sets:from_list(L))

If order does matter, then the only thing I've come up with is to build an
ets table or gb_set iteratively, adding each element not previously in the
table or set to a list of unique items.  Is there an obvious library
function I'm not seeing?  Feels like there should be lists:unique/1.

More information about the erlang-questions mailing list