comparison lib/ur/list.ur @ 1279:4c367c8f5b2d

List.mapi
author Adam Chlipala <adamc@hcoop.net>
date Sun, 13 Jun 2010 14:13:47 -0400
parents 61c3139eab12
children 4172863d049d
comparison
equal deleted inserted replaced
1278:cd8d2c73ccf4 1279:4c367c8f5b2d
99 | x :: ls => mp' (f x :: acc) ls 99 | x :: ls => mp' (f x :: acc) ls
100 in 100 in
101 mp' [] 101 mp' []
102 end 102 end
103 103
104 fun mapi [a] [b] f =
105 let
106 fun mp' n acc ls =
107 case ls of
108 [] => rev acc
109 | x :: ls => mp' (n + 1) (f n x :: acc) ls
110 in
111 mp' 0 []
112 end
113
104 fun mapPartial [a] [b] f = 114 fun mapPartial [a] [b] f =
105 let 115 let
106 fun mp' acc ls = 116 fun mp' acc ls =
107 case ls of 117 case ls of
108 [] => rev acc 118 [] => rev acc