From 3ac04f901ecfb3fed128759964ccc54fa4ee7b2a Mon Sep 17 00:00:00 2001
From: Anthony Ramine
Calls
That is,
+filtermap(Fun, List1) ->
+ lists:foldr(fun(Elem, Acc) ->
+ case Fun(Elem) of
+ false -> Acc;
+ true -> [Elem|Acc];
+ {true,Value} -> [Value|Acc]
+ end,
+ end, [], List1).
+ Example:
++> lists:filtermap(fun(X) -> case X rem 2 of 0 -> {true, X div 2}; _ -> false end end, [1,2,3,4,5]). +[1,2]+