1 %%%----------------------------------------------------------------------------
2 %%% Equivalent to stdlib's orddict, but with a pretty (IMO), uniform interface.
3 %%%----------------------------------------------------------------------------
6 -behavior(hope_dictionary).
31 %% ============================================================================
33 %% ============================================================================
41 case lists:keyfind(K, 1, T)
47 lists:keystore(K, 1, T, {K, V}).
52 % TODO: Eliminate the 2nd lookup.
56 case lists:keytake(K, 1, T1)
57 of {value, {K, V}, T2} -> {{some, V}, T2}
58 ; false -> {none , T1}
66 F2 = fun ({K, _}=X) -> {K, apply_map(F1, X)} end,
73 fold(T, F1, Accumulator) ->
74 F2 = fun ({K, V}, Acc) -> F1(K, V, Acc) end,
75 lists:foldl(F2, Accumulator, T).
81 % TODO: Decide if validation is to be done here. Do so if yes.
85 %% ============================================================================
87 %% ============================================================================
91 when F :: fun(( K, V1 ) -> V2)
92 , G :: fun(({K, V1}) -> V2)
95 fun (X) -> apply_map(F, X) end.
97 -spec apply_map(fun((K, V1) -> V2), {K, V1}) ->
99 apply_map(F, {K, V}) ->