%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% @doc The Map Functor. %%% @end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%_* Module declaration ====================================================== -module(do_map). -behaviour(do_functor). %%%_* Exports ================================================================= -define(API, [fmap/2]). -export(?API). -ignore_xref(?API). %%%_* Includes ================================================================ -include("do_macros.hrl"). -include("do_types.hrl"). %%%_* Code ==================================================================== %%%_* functor ----------------------------------------------------------------- -spec fmap(fn(A, B), map(A)) -> map(B). fmap(F, Map) when ?isF1(F) -> maps:map(fun(_, V) -> F(V) end, Map). %%%_* Tests =================================================================== -ifdef(TEST). -include_lib("eunit/include/eunit.hrl"). sequence_map_test() -> F = fun(A) -> A + 1 end, ?assertEqual(#{a => 2, b => 3}, fmap(F, #{a => 1, b => 2})). -endif.