diff options
author | Björn-Egil Dahlberg <[email protected]> | 2015-05-14 22:10:32 +0200 |
---|---|---|
committer | Björn-Egil Dahlberg <[email protected]> | 2015-05-18 10:58:25 +0200 |
commit | c604ae034a79c3ca8d084de432b51af2affb2c48 (patch) | |
tree | 722dac111b9d9dceca6028025e79b531c3c9dda0 /lib/stdlib/src | |
parent | 40732b962a7bf6300f82f5662a68df2f940b2026 (diff) | |
download | otp-c604ae034a79c3ca8d084de432b51af2affb2c48.tar.gz otp-c604ae034a79c3ca8d084de432b51af2affb2c48.tar.bz2 otp-c604ae034a79c3ca8d084de432b51af2affb2c48.zip |
stdlib: Add maps:filter/2
Diffstat (limited to 'lib/stdlib/src')
-rw-r--r-- | lib/stdlib/src/maps.erl | 16 |
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(), |