proplists:normalize/2
对列表里元素进行一系列的替换/扩展操作
用法:
normalize(ListIn, Stages) -> ListOut
内部实现:
-spec normalize(ListIn, Stages) -> ListOut when ListIn :: [term()], Stages :: [Operation], Operation :: {'aliases', Aliases} | {'negations', Negations} | {'expand', Expansions}, Aliases :: [{Key, Key}], Negations :: [{Key, Key}], Expansions :: [{Property :: property(), Expansion :: [term()]}], ListOut :: [term()]. normalize(L, [{aliases, As} | Xs]) -> normalize(substitute_aliases(As, L), Xs); normalize(L, [{expand, Es} | Xs]) -> normalize(expand(Es, L), Xs); normalize(L, [{negations, Ns} | Xs]) -> normalize(substitute_negations(Ns, L), Xs); normalize(L, []) -> compact(L).
对列表里元素进行替换/扩展等一系列操作。对于一个 aliases 操作,函数 proplists:substitute_aliases/2 将调用给定的 aliases 列表;对于一个 negations 操作,函数 proplists:substitute_negations/2 将调用给定的 negation 列表;对于一个 expand 操作,函数 proplists:expand/2 将调用给定的 expansions 列表。最后的结果将自动被函数 proplists:compact/1 进行压缩操作。
proplists:normalize([a, b, c, d], [{aliases, [{a, apple}, {b, banana}]}]).
proplists:normalize([a, b, c, d], [{expand, [{d, [d, e, f, g]}]}]).
proplists:normalize([a, b, c, d], [{aliases, [{a, apple}, {b, banana}]}, {expand, [{d, [d, e, f, g]}]}]).
proplists:normalize([a, b, c, d], [{expand, [{d, [d, e, f, g]}]}, {aliases, [{a, apple}, {b, banana}]}]).