Skip to content

Commit

Permalink
[#1] get/[2,3] to access values in nested maps.
Browse files Browse the repository at this point in the history
  • Loading branch information
jfacorro committed Aug 12, 2014
1 parent e1fdf03 commit 02f5ec7
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ logs
bin
ebin
deps
.erlang.mk.*
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,10 @@
PROJECT = katana

DEPS = sync

dep_sync = git https://github.com/rustyio/sync.git master

include erlang.mk

shell: app
erl -pa ebin -pa deps/*/ebin -s sync
28 changes: 28 additions & 0 deletions src/katana_maps.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
-module(katana_maps).

-export([
get/2,
get/3
]).

-spec get(term(), map()) -> term().
get(Keys, Map) ->
get(Keys, Map, undefined).

-spec get(term(), map(), term()) -> term().
get([Key], Map, Default) ->
get(Key, Map, Default);
get([Key | Rest], Map, Default) ->
case get(Key, Map, Default) of
NewMap when is_map(NewMap) ->
get(Rest, NewMap, Default);
_ ->
Default
end;
get(Key, Map, Default) ->
case maps:is_key(Key, Map) of
true ->
maps:get(Key, Map);
false ->
Default
end.

0 comments on commit 02f5ec7

Please sign in to comment.