diff options
author | Fredrik Gustafsson <[email protected]> | 2013-05-02 11:28:40 +0200 |
---|---|---|
committer | Fredrik Gustafsson <[email protected]> | 2013-05-02 11:28:40 +0200 |
commit | 7fd1f9be22e8b5fea2c8363770f7dba1a14f81d4 (patch) | |
tree | 5ff85694e83d9c428b40a3526f795ff97171cb79 /lib/stdlib/src | |
parent | 49edd0102919a1dcf673cb34634fb89fa55f505a (diff) | |
parent | f717cdd28f4a0382db18239622a4a0ba30b29336 (diff) | |
download | otp-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.erl | 24 |
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()), |