aboutsummaryrefslogtreecommitdiffstats
path: root/lib/stdlib/src
diff options
context:
space:
mode:
authorFredrik Gustafsson <[email protected]>2013-05-02 11:28:40 +0200
committerFredrik Gustafsson <[email protected]>2013-05-02 11:28:40 +0200
commit7fd1f9be22e8b5fea2c8363770f7dba1a14f81d4 (patch)
tree5ff85694e83d9c428b40a3526f795ff97171cb79 /lib/stdlib/src
parent49edd0102919a1dcf673cb34634fb89fa55f505a (diff)
parentf717cdd28f4a0382db18239622a4a0ba30b29336 (diff)
downloadotp-7fd1f9be22e8b5fea2c8363770f7dba1a14f81d4.tar.gz
otp-7fd1f9be22e8b5fea2c8363770f7dba1a14f81d4.tar.bz2
otp-7fd1f9be22e8b5fea2c8363770f7dba1a14f81d4.zip
Merge branch 'maint'
Diffstat (limited to 'lib/stdlib/src')
-rw-r--r--lib/stdlib/src/lists.erl24
1 files changed, 17 insertions, 7 deletions
diff --git a/lib/stdlib/src/lists.erl b/lib/stdlib/src/lists.erl
index 961c060019..0c033acd88 100644
--- a/lib/stdlib/src/lists.erl
+++ b/lib/stdlib/src/lists.erl
@@ -36,7 +36,7 @@
-export([merge/3, rmerge/3, sort/2, umerge/3, rumerge/3, usort/2]).
-export([all/2,any/2,map/2,flatmap/2,foldl/3,foldr/3,filter/2,
- partition/2,zf/2,
+ partition/2,zf/2,filtermap/2,
mapfoldl/3,mapfoldr/3,foreach/2,takewhile/2,dropwhile/2,splitwith/2,
split/2]).
@@ -1291,18 +1291,28 @@ partition(Pred, [H | T], As, Bs) ->
partition(Pred, [], As, Bs) when is_function(Pred, 1) ->
{reverse(As), reverse(Bs)}.
--spec zf(fun((T) -> boolean() | {'true', X}), [T]) -> [(T | X)].
+-spec filtermap(Fun, List1) -> List2 when
+ Fun :: fun((Elem) -> boolean() | {'true', Value}),
+ List1 :: [Elem],
+ List2 :: [Elem | Value],
+ Elem :: term(),
+ Value :: term().
-zf(F, [Hd|Tail]) ->
+filtermap(F, [Hd|Tail]) ->
case F(Hd) of
true ->
- [Hd|zf(F, Tail)];
+ [Hd|filtermap(F, Tail)];
{true,Val} ->
- [Val|zf(F, Tail)];
+ [Val|filtermap(F, Tail)];
false ->
- zf(F, Tail)
+ filtermap(F, Tail)
end;
-zf(F, []) when is_function(F, 1) -> [].
+filtermap(F, []) when is_function(F, 1) -> [].
+
+-spec zf(fun((T) -> boolean() | {'true', X}), [T]) -> [(T | X)].
+
+zf(F, L) ->
+ filtermap(F, L).
-spec foreach(Fun, List) -> ok when
Fun :: fun((Elem :: T) -> term()),