Last active
August 29, 2015 14:26
-
-
Save varnerac/594b065efcc5b54e26d4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%% Map keys known at compile-time | |
%% No boilerplate code or parse transform for record -> JSON | |
%% Matching on map keys in function signatures, not possible with proplists | |
%% JSONFrags = [#{...}, #{...}, #{...}, | |
process_layers(JSONFrags) -> process_layers(JSONFrags, #{}). | |
process_layers([], Result) -> | |
jsx:encode(Result). | |
process_layers([#{<<"key">> := <<"value">>} | Rest], Result) -> | |
process_layers(Rest, Result{<<"new_name">> => <<"Value">>}); | |
process_layers([#{<<"key2">> := <<"value2">>} | Rest], #{<<"key3">> := _} = Result) -> | |
process_layers(Rest, Result); | |
process_layers([#{<<"key2">> := <<"value2">>} = Layer | Rest], Result) -> | |
[<<"Name">>, <<"Label">>, <<"Type">>] = maps:get(<<"Columns">>,Layer), | |
[[Name, _Label, _Type]] = maps:get(<<"Rows">>,Layer), | |
process_layers(Rest, Result#{<<"new_name">> => Name}). | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment