% $Id: MaxAmounts.oz,v 1.3 2010/03/31 22:09:50 leavens Exp leavens $ declare %% The SalesData gammar: %% ::= store(address: amounts: ) %% | group(name: members: ) fun {MaxAmounts SalesData} case SalesData of store(address: Addr amounts: Amts) then store(address: Addr amounts: [{FoldR Amts Max 0}]) [] group(name:Name members: Mems) then group(name:Name members: {Map Mems MaxAmounts}) end end % Or instead of using {FoldR Amts Max 0} above you could call the following % to process the list of amounts looking for the maximum element fun {ListMax Lst} case Lst of H|T then {Max H {ListMax T}} else 0 end end % Or instead of using {Map Mems MaxAmount} above you could call the following % to run MaxAmounts on each element in the list of members. fun {MaxAmountsList LOSD} case LOSD of D|Rest then {MaxAmounts D} | {MaxAmountsList Rest} else nil end end