[m-rev.] diff: add list.map_foldr/5
Julien Fischer
jfischer at opturion.com
Fri Dec 27 14:39:58 AEDT 2013
Branches: main
--------
Add list.map_foldr/5.
library/list.m:
As above.
NEWS:
Announce the addition.
Julien.
diff --git a/NEWS b/NEWS
index e77be99..e34d201 100644
--- a/NEWS
+++ b/NEWS
@@ -18,8 +18,8 @@ Changes to the Mercury standard library:
* We have added the following predicates and functions to the map module:
det_min_key/1, det_max_key/1, foldl2_values/6 and foldl3_values/8.
-* We have added the following predicates to the list module: foldr2/6 and
- foldr3/8.
+* We have added the following predicates to the list module: foldr2/6,
+ foldr3/8 and map_foldlr/5.
* We have added the following predicates to the bag module: foldl/4 and
foldl2/6.
diff --git a/library/list.m b/library/list.m
index d3f1856..0ace715 100644
--- a/library/list.m
+++ b/library/list.m
@@ -1170,12 +1170,12 @@
% returned in End.
%
:- pred list.map_foldl(pred(L, M, A, A), list(L), list(M), A, A).
-:- mode list.map_foldl(pred(in, out, di, uo) is det, in, out, di, uo)
- is det.
:- mode list.map_foldl(pred(in, out, in, out) is det, in, out, in, out)
is det.
:- mode list.map_foldl(pred(in, out, mdi, muo) is det, in, out, mdi, muo)
is det.
+:- mode list.map_foldl(pred(in, out, di, uo) is det, in, out, di, uo)
+ is det.
:- mode list.map_foldl(pred(in, out, in, out) is semidet, in, out, in, out)
is semidet.
:- mode list.map_foldl(pred(in, out, mdi, muo) is semidet, in, out, mdi, muo)
@@ -1470,6 +1470,28 @@
:- mode list.map4_foldl(pred(in, out, out, out, out, di, uo) is cc_multi,
in, out, out, out, out, di, uo) is cc_multi.
+ % list.map_foldr(Pred, InList, OutList, Start, End) calls Pred
+ % with an accumulator (with the initial value of Start) on
+ % each element of InList (working right-to-left) to transform
+ % InList into OutList. The final value of the accumulator is
+ % returned in End.
+ %
+:- pred list.map_foldr(pred(L, M, A, A), list(L), list(M), A, A).
+:- mode list.map_foldr(pred(in, out, in, out) is det, in, out, in, out)
+ is det.
+:- mode list.map_foldr(pred(in, out, mdi, muo) is det, in, out, mdi, muo)
+ is det.
+:- mode list.map_foldr(pred(in, out, di, uo) is det, in, out, di, uo)
+ is det.
+:- mode list.map_foldr(pred(in, out, in, out) is semidet, in, out, in, out)
+ is semidet.
+:- mode list.map_foldr(pred(in, out, mdi, muo) is semidet, in, out, mdi, muo)
+ is semidet.
+:- mode list.map_foldr(pred(in, out, di, uo) is semidet, in, out, di, uo)
+ is semidet.
+:- mode list.map_foldr(pred(in, in, di, uo) is semidet, in, in, di, uo)
+ is semidet.
+
% list.filter_map_foldl(Transformer, List, TrueList, Start, End):
% Takes a predicate with one input argument, one output argument and an
% accumulator. It is called with each element of List. If a call succeeds,
@@ -2780,6 +2802,11 @@ list.map4_foldl(P, [H0 | T0], [H1 | T1], [H2 | T2], [H3 | T3], [H4 | T4], !A) :-
P(H0, H1, H2, H3, H4, !A),
list.map4_foldl(P, T0, T1, T2, T3, T4, !A).
+list.map_foldr(_, [], [], !A).
+list.map_foldr(P, [H0 | T0], [H | T], !A) :-
+ list.map_foldr(P, T0, T, !A),
+ P(H0, H, !A).
+
list.filter_map_foldl(_, [], [], !A).
list.filter_map_foldl(P, [X | Xs], True, !A) :-
( P(X, Y, !A) ->
More information about the reviews
mailing list