aboutsummaryrefslogtreecommitdiffstats
path: root/lib/stdlib/src
diff options
context:
space:
mode:
authorBjörn-Egil Dahlberg <[email protected]>2014-05-26 16:38:50 +0200
committerBjörn-Egil Dahlberg <[email protected]>2014-05-26 16:38:50 +0200
commit6b6cd01b607a1bfcf61bb6d5f4cc3fe9b37445db (patch)
tree3e6200ef0f4c9563957daac8f14298faeb314094 /lib/stdlib/src
parent6731d295915448e4c219f1db1b146264ced68018 (diff)
parent47463022cea3b7ca89124c1607cf10b92fbb536f (diff)
downloadotp-6b6cd01b607a1bfcf61bb6d5f4cc3fe9b37445db.tar.gz
otp-6b6cd01b607a1bfcf61bb6d5f4cc3fe9b37445db.tar.bz2
otp-6b6cd01b607a1bfcf61bb6d5f4cc3fe9b37445db.zip
Merge branch 'saa/add_default_value_for_maps_get/OTP-11951' into maint
* saa/add_default_value_for_maps_get/OTP-11951: stdlib: Fix indentation of maps doc Add docs and test for maps:get/3 Add default value for maps:get
Diffstat (limited to 'lib/stdlib/src')
-rw-r--r--lib/stdlib/src/maps.erl18
1 files changed, 17 insertions, 1 deletions
diff --git a/lib/stdlib/src/maps.erl b/lib/stdlib/src/maps.erl
index fd6d56fa47..4ef1638e6d 100644
--- a/lib/stdlib/src/maps.erl
+++ b/lib/stdlib/src/maps.erl
@@ -23,7 +23,8 @@
fold/3,
map/2,
size/1,
- without/2
+ without/2,
+ get/3
]).
@@ -142,6 +143,21 @@ values(_) -> erlang:nif_error(undef).
%%% End of BIFs
+-spec get(Key, Map, Default) -> Value | Default when
+ Key :: term(),
+ Map :: map(),
+ Value :: term(),
+ Default :: term().
+
+get(Key, Map, Default) ->
+ case maps:find(Key, Map) of
+ {ok, Value} ->
+ Value;
+ error ->
+ Default
+ end.
+
+
-spec fold(Fun,Init,Map) -> Acc when
Fun :: fun((K, V, AccIn) -> AccOut),
Init :: term(),