Mercurial > urweb
diff src/list_util.sml @ 849:e571fb150a9f
Fix a bug in type class enrichment from substructures
author | Adam Chlipala <adamc@hcoop.net> |
---|---|
date | Tue, 16 Jun 2009 14:38:01 -0400 |
parents | 0f7e2cca6d9b |
children |
line wrap: on
line diff
--- a/src/list_util.sml Sat Jun 13 15:42:24 2009 -0400 +++ b/src/list_util.sml Tue Jun 16 14:38:01 2009 -0400 @@ -123,6 +123,24 @@ 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 @@ 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 =