From 4dce690086c8d6132c22d5c47a0561a4b1261293 Mon Sep 17 00:00:00 2001 From: Adam Chlipala Date: Tue, 16 Jun 2009 14:38:01 -0400 Subject: Fix a bug in type class enrichment from substructures --- src/list_util.sml | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'src/list_util.sml') diff --git a/src/list_util.sml b/src/list_util.sml index 1f6b24ee..03c9549e 100644 --- a/src/list_util.sml +++ b/src/list_util.sml @@ -123,6 +123,24 @@ fun foldlMapPartial f s = fm ([], s) end +fun foldlMapiPartial f s = + let + fun fm (n, ls', s) ls = + case ls of + nil => (rev ls', s) + | h :: t => + let + val (h', s') = f (n, h, s) + val ls' = case h' of + NONE => ls' + | SOME h' => h' :: ls' + in + fm (n + 1, ls', s') t + end + in + fm (0, [], s) + end + fun foldlMapAbort f s = let fun fm (ls', s) ls = @@ -172,6 +190,19 @@ fun mapi f = m 0 [] end +fun mapiPartial f = + let + fun m i acc ls = + case ls of + [] => rev acc + | h :: t => + m (i + 1) (case f (i, h) of + NONE => acc + | SOME v => v :: acc) t + in + m 0 [] + end + fun appi f = let fun m i ls = -- cgit v1.2.3