diff options
author | Björn-Egil Dahlberg <[email protected]> | 2013-10-24 18:13:31 +0200 |
---|---|---|
committer | Björn-Egil Dahlberg <[email protected]> | 2014-01-28 17:06:44 +0100 |
commit | 1a234c9eba8ac2c78f97e5f3e33521b8cc5d3748 (patch) | |
tree | 5933a3218a0858a63948d8469384f09b5992dea5 /lib/stdlib | |
parent | 5dda9e038891500a0849a3bf4d1079a355cdd30f (diff) | |
download | otp-1a234c9eba8ac2c78f97e5f3e33521b8cc5d3748.tar.gz otp-1a234c9eba8ac2c78f97e5f3e33521b8cc5d3748.tar.bz2 otp-1a234c9eba8ac2c78f97e5f3e33521b8cc5d3748.zip |
stdlib: Strengthen Map module with guards
This commit requires Map enabled bootstrap compiler.
Diffstat (limited to 'lib/stdlib')
-rw-r--r-- | lib/stdlib/src/maps.erl | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/lib/stdlib/src/maps.erl b/lib/stdlib/src/maps.erl index 59ac80b46c..0e6a1ddb1a 100644 --- a/lib/stdlib/src/maps.erl +++ b/lib/stdlib/src/maps.erl @@ -164,7 +164,7 @@ values(_) -> erlang:nif_error(undef). K :: term(), V :: term(). -foldl(Fun, Init, Map) -> +foldl(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 @@ -177,7 +177,7 @@ foldl(Fun, Init, Map) -> K :: term(), V :: term(). -foldr(Fun, Init, Map) -> +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)). @@ -189,7 +189,7 @@ foldr(Fun, Init, Map) -> V1 :: term(), V2 :: term(). -map(Fun, Map) -> +map(Fun, Map) when is_function(Fun, 2), is_map(Map) -> maps:from_list(lists:map(fun ({K,V}) -> {K,Fun(K,V)} @@ -199,14 +199,15 @@ map(Fun, Map) -> -spec size(Map) -> non_neg_integer() when Map :: map(). -size(Map) -> +size(Map) when is_map(Map) -> erlang:map_size(Map). + -spec without(Ks,Map1) -> Map2 when Ks :: [K], Map1 :: map(), Map2 :: map(), K :: term(). -without(Ks, M) -> +without(Ks, M) when is_list(Ks), is_map(M) -> maps:from_list([{K,V}||{K,V} <- maps:to_list(M), not lists:member(K, Ks)]). |