To name a function

Attila Rajmund Nohl <>
Wed Dec 15 17:06:54 CET 2010


Hello!

I've found at least places in my code where I'd need a function which
decides if all, some or none members of a list have a particular
property (the list always has at least one element). How to name this
function? The code is something like this:

f(_F, []) ->
  erlang:error({badarg, []});

f(F, L) ->
  {Has, Not} =
    lists:foldr(
      fun(E, {H, N}) ->
        case f(E) of
          true -> {H+1, N};
          false -> {H, N+1}
        end
      end, {0,0}, L),
  case {Has, Not} of
    {0, _} -> none;
    {_, 0} -> all;
    _ -> some
  end.


More information about the erlang-questions mailing list