%% Generate advertisements. RiotAds = declare(set), RovioAds = declare(set), create_advertisements_and_contracts(RiotAds, Contracts), create_advertisements_and_contracts(RovioAds, Contracts), %% Union ads. Ads = declare(set), union(RovioAds, RiotAds, Ads), %% Compute the product of both ads and contracts. AdsContracts = declare(set), product(Ads, Contracts, AdsContracts), %% Filter items by join on item it. AdsWithContracts = declare(set), FilterFun = fun({#ad{id=Id1}, #contract{id=Id2}}) -> Id1 =:= Id2 end, filter(AdsContracts, FilterFun, AdsWithContracts).