aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBjörn-Egil Dahlberg <[email protected]>2014-01-27 16:00:34 +0100
committerBjörn-Egil Dahlberg <[email protected]>2014-01-29 11:08:50 +0100
commit335e6bf3e4987e5f549136c1f692c628b1dfc360 (patch)
tree03391041ce3e27daec19806a72e08652079b2d82
parent543074e7aab966a597e405bc52c94e57358663a5 (diff)
downloadotp-335e6bf3e4987e5f549136c1f692c628b1dfc360.tar.gz
otp-335e6bf3e4987e5f549136c1f692c628b1dfc360.tar.bz2
otp-335e6bf3e4987e5f549136c1f692c628b1dfc360.zip
stdlib: Make maps:fold/3 order-independent
This means replacing maps:foldl/3 and maps:foldr/3 with maps:fold/3.
-rw-r--r--lib/stdlib/src/maps.erl21
1 files changed, 3 insertions, 18 deletions
diff --git a/lib/stdlib/src/maps.erl b/lib/stdlib/src/maps.erl
index 0e6a1ddb1a..41de174e7d 100644
--- a/lib/stdlib/src/maps.erl
+++ b/lib/stdlib/src/maps.erl
@@ -20,8 +20,7 @@
-module(maps).
-export([
- foldl/3,
- foldr/3,
+ fold/3,
map/2,
size/1,
without/2
@@ -154,7 +153,7 @@ values(_) -> erlang:nif_error(undef).
%%% End of BIFs
--spec foldl(Fun,Init,Map) -> Acc when
+-spec fold(Fun,Init,Map) -> Acc when
Fun :: fun((K, V, AccIn) -> AccOut),
Init :: term(),
Acc :: term(),
@@ -164,23 +163,9 @@ values(_) -> erlang:nif_error(undef).
K :: term(),
V :: term().
-foldl(Fun, Init, Map) when is_function(Fun,3), is_map(Map) ->
+fold(Fun, Init, Map) when is_function(Fun,3), is_map(Map) ->
lists:foldl(fun({K,V},A) -> Fun(K,V,A) end,Init,maps:to_list(Map)).
--spec foldr(Fun,Init,Map) -> Acc when
- Fun :: fun((K,V,AccIn) -> AccOut),
- Init :: term(),
- Acc :: term(),
- AccIn :: term(),
- AccOut :: term(),
- Map :: map(),
- K :: term(),
- V :: term().
-
-foldr(Fun, Init, Map) when is_function(Fun,3), is_map(Map) ->
- lists:foldr(fun({K,V},A) -> Fun(K,V,A) end,Init,maps:to_list(Map)).
-
-
-spec map(Fun,Map1) -> Map2 when
Fun :: fun((K, V1) -> V2),
Map1 :: map(),