aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorBjörn-Egil Dahlberg <[email protected]>2015-05-14 22:10:32 +0200
committerBjörn-Egil Dahlberg <[email protected]>2015-05-18 10:58:25 +0200
commitc604ae034a79c3ca8d084de432b51af2affb2c48 (patch)
tree722dac111b9d9dceca6028025e79b531c3c9dda0 /lib
parent40732b962a7bf6300f82f5662a68df2f940b2026 (diff)
downloadotp-c604ae034a79c3ca8d084de432b51af2affb2c48.tar.gz
otp-c604ae034a79c3ca8d084de432b51af2affb2c48.tar.bz2
otp-c604ae034a79c3ca8d084de432b51af2affb2c48.zip
stdlib: Add maps:filter/2
Diffstat (limited to 'lib')
-rw-r--r--lib/stdlib/src/maps.erl16
1 files changed, 15 insertions, 1 deletions
diff --git a/lib/stdlib/src/maps.erl b/lib/stdlib/src/maps.erl
index 3877c150ec..2913a2ff86 100644
--- a/lib/stdlib/src/maps.erl
+++ b/lib/stdlib/src/maps.erl
@@ -19,7 +19,8 @@
-module(maps).
--export([get/3,fold/3, map/2, size/1,
+-export([get/3,filter/2,fold/3, map/2,
+ size/1,
without/2, with/2]).
@@ -145,6 +146,19 @@ get(Key,Map,Default) ->
erlang:error({badmap,Map},[Key,Map,Default]).
+-spec filter(Pred,Map1) -> Map2 when
+ Pred :: fun((Key, Value) -> boolean()),
+ Key :: term(),
+ Value :: term(),
+ Map1 :: map(),
+ Map2 :: map().
+
+filter(Pred,Map) when is_function(Pred,2), is_map(Map) ->
+ maps:from_list([{K,V}||{K,V}<-maps:to_list(Map),Pred(K,V)]);
+filter(Pred,Map) ->
+ erlang:error(error_type(Map),[Pred,Map]).
+
+
-spec fold(Fun,Init,Map) -> Acc when
Fun :: fun((K, V, AccIn) -> AccOut),
Init :: term(),