@@ -57,6 +57,63 @@ prop_search_not_found() ->
5757 end
5858 ).
5959
60+ - spec prop_zipfold () -> proper :test ().
61+ prop_zipfold () ->
62+ ? FORALL (
63+ [Left , Right ],
64+ [map (), map ()],
65+ begin
66+ CommonKeys = maps_common_keys (Left , Right ),
67+
68+ Actual =
69+ genlib_map :zipfold (
70+ fun (Key , LValue , RValue , Acc ) -> Acc #{Key => {LValue , RValue }} end ,
71+ #{},
72+ Left ,
73+ Right
74+ ),
75+
76+ Expected =
77+ maps_merge_with (
78+ fun (_Key , LValue , RValue ) -> {LValue , RValue } end ,
79+ Left ,
80+ Right
81+ ),
82+
83+ Actual =:= maps :with (CommonKeys , Expected )
84+ end
85+ ).
86+
87+ - if (? OTP_RELEASE >= 24 ).
88+
89+ maps_merge_with (Combiner , Left , Right ) ->
90+ maps :merge_with (Combiner , Left , Right ).
91+
92+ - else .
93+
94+ maps_merge_with (Combiner , Left , Right ) ->
95+ CommonMerged =
96+ lists :foldl (
97+ fun (Key , Acc ) ->
98+ Acc #{Key => Combiner (Key , maps :get (Key , Left ), maps :get (Key , Right ))}
99+ end ,
100+ #{},
101+ maps_common_keys (Left , Right )
102+ ),
103+
104+ maps :merge (maps :merge (Left , Right ), CommonMerged ).
105+
106+ % % END -if(?OTP_RELEASE >= 24).
107+ - endif .
108+
109+ maps_common_keys (LeftMap , RightMap ) ->
110+ sets :to_list (
111+ sets :intersection (
112+ sets :from_list (maps :keys (LeftMap )),
113+ sets :from_list (maps :keys (RightMap ))
114+ )
115+ ).
116+
60117map () ->
61118 ? LET (KVList , list ({term (), term ()}), maps :from_list (KVList )).
62119
0 commit comments