[erlang-questions] To name a function

Pierpaolo Bernardi <>
Thu Dec 16 11:57:10 CET 2010


Here's my try (not tested).
It scans the list once, stops early, and all the hard work is made by
library functions!

categorize(P, [X|Xs]) ->
  case P(X) of
    true ->
      case lists:all(P, Xs) of
        true -> all
        false -> some
      end
    false ->
      case lists:any(P, Xs) of
        true -> some
        false -> none
      end
  end.

Cheers
P.


More information about the erlang-questions mailing list