diff options
author | Fredrik Gustafsson <[email protected]> | 2013-05-02 11:09:24 +0200 |
---|---|---|
committer | Fredrik Gustafsson <[email protected]> | 2013-05-02 11:09:24 +0200 |
commit | f7c5df146f027d0dbcbcc0e41f39343b74cedfd2 (patch) | |
tree | b1fc855d5767b32ae50c5a592bb5993d4c63f0e6 /lib/stdlib/src | |
parent | cd14a151051567cc19dfa3677799612366060801 (diff) | |
parent | 3ac04f901ecfb3fed128759964ccc54fa4ee7b2a (diff) | |
download | otp-f7c5df146f027d0dbcbcc0e41f39343b74cedfd2.tar.gz otp-f7c5df146f027d0dbcbcc0e41f39343b74cedfd2.tar.bz2 otp-f7c5df146f027d0dbcbcc0e41f39343b74cedfd2.zip |
Merge branch 'nox/lists-filtermap/OTP-11078' into maint
* nox/lists-filtermap/OTP-11078:
Rename and document lists:zf/2 as lists:filtermap/2
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()), |