1%% 2%% %CopyrightBegin% 3%% 4%% Copyright Ericsson AB 2013-2016. All Rights Reserved. 5%% 6%% Licensed under the Apache License, Version 2.0 (the "License"); 7%% you may not use this file except in compliance with the License. 8%% You may obtain a copy of the License at 9%% 10%% http://www.apache.org/licenses/LICENSE-2.0 11%% 12%% Unless required by applicable law or agreed to in writing, software 13%% distributed under the License is distributed on an "AS IS" BASIS, 14%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15%% See the License for the specific language governing permissions and 16%% limitations under the License. 17%% 18%% %CopyrightEnd% 19%% 20 21-module(maps_inline_test). 22 23-export([?MODULE/0]). 24 25?MODULE() -> 26 21 = mval(#{val => 1}) + 27 mval(#{val => 2}) + 28 mval(#{val => 3}) + 29 mval(#{val => 4}) + 30 mval(#{val => 5}) + 31 mval(#{val => 6}), 32 33 21 = gval(#{id => 1}) + 34 gval(#{id => 2}) + 35 gval(#{id => 3}) + 36 gval(#{id => 4}) + 37 gval(#{id => 5}) + 38 gval(#{id => 6}), 39 40 21 = sval(#{id => 1}) + 41 sval(#{id => 2}) + 42 sval(#{id => 3}) + 43 sval(#{id => 4}) + 44 sval(#{id => 5}) + 45 sval(#{id => 6}), 46 47 M = #{v => 1, m => #{v => 21, m => #{v => 7, m => 13}}}, 48 49 42 = decompose(M). 50 51% switch key orders 52decompose(#{ m := M, v := V}) when is_map(M) -> 53 V + decompose(M); 54decompose(#{ v := V, m := M}) -> V + M. 55 56 57mval(#{val := V}) -> V. 58 59sval(#{id := 1}) -> 6; 60sval(#{id := 2}) -> 5; 61sval(#{id := 3}) -> 4; 62sval(#{id := 4}) -> 3; 63sval(#{id := 5}) -> 2; 64sval(#{id := 6}) -> 1. 65 66gval(M) when is_map(M) andalso M =:= #{ id => 1} -> 1; 67gval(M) when is_map(M) andalso M =:= #{ id => 2} -> 4; 68gval(M) when is_map(M) andalso M =:= #{ id => 3} -> 2; 69gval(M) when is_map(M) andalso M =:= #{ id => 4} -> 5; 70gval(M) when is_map(M) andalso M =:= #{ id => 5} -> 3; 71gval(M) when is_map(M) andalso M =:= #{ id => 6} -> 6. 72