1 |
|
%% Copyright (c) 2023 Peter Morgan <peter.james.morgan@gmail.com> |
2 |
|
%% |
3 |
|
%% Licensed under the Apache License, Version 2.0 (the "License"); |
4 |
|
%% you may not use this file except in compliance with the License. |
5 |
|
%% You may obtain a copy of the License at |
6 |
|
%% |
7 |
|
%% http://www.apache.org/licenses/LICENSE-2.0 |
8 |
|
%% |
9 |
|
%% Unless required by applicable law or agreed to in writing, software |
10 |
|
%% distributed under the License is distributed on an "AS IS" BASIS, |
11 |
|
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 |
|
%% See the License for the specific language governing permissions and |
13 |
|
%% limitations under the License. |
14 |
|
|
15 |
|
|
16 |
|
-module(msmp_enum). |
17 |
|
|
18 |
|
|
19 |
|
-export([into_map/1]). |
20 |
|
-export([priv_consult/1]). |
21 |
|
|
22 |
|
|
23 |
|
priv_consult(Filename) -> |
24 |
6 |
into_map(msmp:priv_consult(Filename)). |
25 |
|
|
26 |
|
|
27 |
|
-spec into_map([atom() | {atom(), integer()}]) -> #{atom() | integer() => integer() | atom()}. |
28 |
|
|
29 |
|
into_map(Enumeration) -> |
30 |
6 |
maps:from_list( |
31 |
|
lists:flatten( |
32 |
|
element( |
33 |
|
1, |
34 |
|
lists:mapfoldl( |
35 |
|
fun |
36 |
|
({Name, Value}, _) -> |
37 |
86 |
{kv_vk(Name, Value), Value + 1}; |
38 |
|
|
39 |
|
(Name, Value) -> |
40 |
41 |
{kv_vk(Name, Value), Value + 1} |
41 |
|
end, |
42 |
|
0, |
43 |
|
Enumeration)))). |
44 |
|
|
45 |
|
|
46 |
|
kv_vk(K, V) -> |
47 |
127 |
[{K, V}, {V, K}]. |