changeset 1279:4c367c8f5b2d

List.mapi
author Adam Chlipala <adamc@hcoop.net>
date Sun, 13 Jun 2010 14:13:47 -0400 (2010-06-13)
parents cd8d2c73ccf4
children 3d06e0f7a6f3
files lib/ur/list.ur lib/ur/list.urs
diffstat 2 files changed, 12 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/lib/ur/list.ur	Sun Jun 13 14:13:06 2010 -0400
+++ b/lib/ur/list.ur	Sun Jun 13 14:13:47 2010 -0400
@@ -101,6 +101,16 @@
         mp' []
     end
 
+fun mapi [a] [b] f =
+    let
+        fun mp' n acc ls =
+            case ls of
+                [] => rev acc
+              | x :: ls => mp' (n + 1) (f n x :: acc) ls
+    in
+        mp' 0 []
+    end
+
 fun mapPartial [a] [b] f =
     let
         fun mp' acc ls =
--- a/lib/ur/list.urs	Sun Jun 13 14:13:06 2010 -0400
+++ b/lib/ur/list.urs	Sun Jun 13 14:13:47 2010 -0400
@@ -22,6 +22,8 @@
 
 val mapPartial : a ::: Type -> b ::: Type -> (a -> option b) -> t a -> t b
 
+val mapi : a ::: Type -> b ::: Type -> (int -> a -> b) -> t a -> t b
+
 val mapX : a ::: Type -> ctx ::: {Unit} -> (a -> xml ctx [] []) -> t a -> xml ctx [] []
 
 val mapM : m ::: (Type -> Type) -> monad m -> a ::: Type -> b ::: Type