From 1a234c9eba8ac2c78f97e5f3e33521b8cc5d3748 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn-Egil=20Dahlberg?= Date: Thu, 24 Oct 2013 18:13:31 +0200 Subject: stdlib: Strengthen Map module with guards This commit requires Map enabled bootstrap compiler. --- lib/stdlib/src/maps.erl | 11 ++++++----- 1 file 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)]). -- cgit v1.2.3