diff options
author | Adam Chlipala <adamc@hcoop.net> | 2009-06-16 14:38:01 -0400 |
---|---|---|
committer | Adam Chlipala <adamc@hcoop.net> | 2009-06-16 14:38:01 -0400 |
commit | b93aa3fc0a1aebc3be9e9a69f926eae0300ba253 (patch) | |
tree | 58dd4551f8c5d971e12e1c704f7abd9d90f3373e /src/list_util.sml | |
parent | 9951d7544ba5deaea67864259001a21c12ff11ea (diff) |
Fix a bug in type class enrichment from substructures
Diffstat (limited to 'src/list_util.sml')
-rw-r--r-- | src/list_util.sml | 31 |
1 files changed, 31 insertions, 0 deletions
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 = |