aboutsummaryrefslogtreecommitdiffstats
path: root/lib/stdlib
diff options
context:
space:
mode:
authorSergey Abramyan <[email protected]>2014-04-12 11:44:19 +0400
committerSergey Abramyan <[email protected]>2014-04-12 11:44:19 +0400
commitad4c02a9d7794727c78d36bd47b7272af3efc523 (patch)
tree9e91e5e9177f154531119b984a29655b82dd9690 /lib/stdlib
parent07b8f441ca711f9812fad9e9115bab3c3aa92f79 (diff)
downloadotp-ad4c02a9d7794727c78d36bd47b7272af3efc523.tar.gz
otp-ad4c02a9d7794727c78d36bd47b7272af3efc523.tar.bz2
otp-ad4c02a9d7794727c78d36bd47b7272af3efc523.zip
Add default value for maps:get
Diffstat (limited to 'lib/stdlib')
-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(),