[erlang-questions] maps and lager: how to handle new type gracefully?

alisdair sullivan alisdairsullivan@REDACTED
Wed Apr 30 07:55:13 CEST 2014


On Apr 29, 2014, at 5:21 AM, Max Lapshin <max.lapshin@REDACTED> wrote:

> huh, rather complicated, but ok, it will work.
> 
> Thanks.
> 

i handled this problem in jsx by adding a `rebar.config.script` with the following contents:

case os:getenv("JSX_NOMAPS") or proplists:get_value(jsx_nomaps, CONFIG, false) of
  false ->
    try file:script("config/maps") of
      {ok, true} -> [{erl_opts, [{d, maps_support}]}] ++ CONFIG;
      _ -> CONFIG
    catch _:_ -> CONFIG
    end;
  _ -> CONFIG
end.

`config/maps` is just

maps:keys(#{0 => false, 1 => true}) == [0,1].

if you use more features of maps you can test for them also with a more complicated expression

then all map related code in jsx itself goes inside ifdefs guarded by `maps_support`


More information about the erlang-questions mailing list