diff options
Diffstat (limited to 'src/list_util.sml')
-rw-r--r-- | src/list_util.sml | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/list_util.sml b/src/list_util.sml index 7d3f8333..e3d8515e 100644 --- a/src/list_util.sml +++ b/src/list_util.sml @@ -45,6 +45,26 @@ fun mapfold f = mf end +fun mapfoldB f = + let + fun mf ctx ls s = + case ls of + nil => S.Continue (nil, s) + | h :: t => + let + val (ctx, r) = f (ctx, h) + in + case r s of + S.Return x => S.Return x + | S.Continue (h', s) => + case mf ctx t s of + S.Return x => S.Return x + | S.Continue (t', s) => S.Continue (h' :: t', s) + end + in + mf + end + fun foldlMap f s = let fun fm (ls', s) ls = |