Commit c5708e8c authored by POTTIER Francois's avatar POTTIER Francois

Added [Misc.mapij].

Reimplemented [mapi] using [mapij].
parent 1cef5c66
......@@ -166,15 +166,20 @@ let foldij start n f accu =
let foldi n f accu =
foldij 0 n f accu
(* [mapi n f] produces the list [ f 0; ... f (n-1) ]. *)
(* [mapij start n f] produces the list [ f start; ... f (n-1) ]. *)
let mapi n f =
let mapij start n f =
List.rev (
foldi n (fun i accu ->
foldij start n (fun i accu ->
f i :: accu
) []
)
(* [mapi n f] produces the list [ f 0; ... f (n-1) ]. *)
let mapi n f =
mapij 0 n f
(* [qfold f accu q] repeatedly takes an element [x] off the queue [q]
and applies [f] to the accumulator and to [x], until [q] becomes
empty. Of course, [f] can add elements to [q] as a side-effect.
......
......@@ -117,6 +117,10 @@ val iteri: int -> (int -> unit) -> unit
val foldi: int -> (int -> 'a -> 'a) -> 'a -> 'a
val foldij: int -> int -> (int -> 'a -> 'a) -> 'a -> 'a
(* [mapij start n f] produces the list [ f start; ... f (n-1) ]. *)
val mapij: int -> int -> (int -> 'a) -> 'a list
(* [mapi n f] produces the list [ f 0; ... f (n-1) ]. *)
val mapi: int -> (int -> 'a) -> 'a list
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment