[erlang-questions] Asserting exact maps

Technion technion@REDACTED
Wed Oct 11 10:47:40 CEST 2017


Hi,


I'm wondering if there is a simple process I can use to verify a map only contains valid variables. Consider the following example:


2> Checkmaps = fun(M) ->
2> #{"one" := One, "two" := _Two} = M,
2>     One end.
#Fun<erl_eval.6.99386804>

% These crash as expected

5> Checkmaps(#{"test" => one }).
** exception error: no match of right hand side value #{"test" => one}
6> Checkmaps(#{"one" => one }).
** exception error: no match of right hand side value #{"one" => one}


% This works as expected

7> Checkmaps(#{"one" => one, "two" => two }).
one

% This however also runs - I would like it to crash like the first example

8> Checkmaps(#{"one" => one, "two" => two, "three" => test }).

one


The use case here is I'm pulling external data - anything I'm not expecting is not a happy path. Any assistance appreciated.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20171011/aea65f95/attachment.htm>


More information about the erlang-questions mailing list