[erlang-questions] lists:filter/2

Dominic Williams erlang@REDACTED
Fri Jan 11 08:53:28 CET 2008


Hi Doug,

> Does lists:filter(Pred, List1) -> List2
> 
> guarantee to return the filtered items in List2
> in the same relative order as unfiltered List1?

If you check the code of lists.erl, you'll find filter/2 is 
implemented using a list comprehension:

filter(Pred, List) when is_function(Pred, 1) ->
     [ E || E <- List, Pred(E) ].

List comprehensions definitely preserve order.

Regards,

Dominic Williams
http://dominicwilliams.net

----



More information about the erlang-questions mailing list