Files
mercury/tests/hard_coded/map_fold.m
Ralph Becket 9d72f5cc85 Add the foldr family to map and tree234.
Estimated hours taken: 2
Branches: main

Add the foldr family to map and tree234.

NEWS:
	Mention this change.

library/map.m:
library/tree234.m:
	Added the foldr family.

tests/hard_coded/Mmakefile:
tests/hard_coded/map_fold.exp:
tests/hard_coded/map_fold.m:
	Add a test case for map.foldl/foldr.
2007-07-30 06:03:08 +00:00

39 lines
1.1 KiB
Mathematica

%-----------------------------------------------------------------------------%
% map_fold.m
% Ralph Becket <rafe@csse.unimelb.edu.au>
% Fri Jul 13 12:50:24 EST 2007
% vim: ft=mercury ts=4 sw=4 et wm=0 tw=0
%
% Test map.fold[lr].
%
%-----------------------------------------------------------------------------%
:- module map_fold.
:- interface.
:- import_module io.
:- pred main(io::di, io::uo) is det.
%-----------------------------------------------------------------------------%
%-----------------------------------------------------------------------------%
:- implementation.
:- import_module int, list, map.
%-----------------------------------------------------------------------------%
main(!IO) :-
Map = list.foldl(func(I, M) = M ^ elem(I) := I, 1..10, map.init),
L = map.foldl(func(K, V, Xs) = [K, V | Xs], Map, []),
R = map.foldr(func(K, V, Xs) = [K, V | Xs], Map, []),
io.print(L, !IO), io.nl(!IO),
io.print(R, !IO), io.nl(!IO).
%-----------------------------------------------------------------------------%
%-----------------------------------------------------------------------------%