@@ -1294,6 +1294,12 @@ val map2i : (int -> 'a -> 'b -> 'c ) -> 'a array -> 'b array -> 'c array
12941294
12951295val to_list_map : ('a -> 'b option) -> 'a array -> 'b list
12961296
1297+ val to_list_map_acc :
1298+ ('a -> 'b option) ->
1299+ 'a array ->
1300+ 'b list ->
1301+ 'b list
1302+
12971303val of_list_map : ('a -> 'b) -> 'a list -> 'b array
12981304
12991305val rfind_with_index : 'a array -> ('a -> 'b -> bool) -> 'b -> int
@@ -1414,15 +1420,20 @@ let map2i f a b =
14141420 else
14151421 Array.mapi (fun i a -> f i a ( Array.unsafe_get b i )) a
14161422
1417- let to_list_map f a =
1418- let rec tolist i res =
1423+
1424+ let rec tolist_aux a f i res =
14191425 if i < 0 then res else
14201426 let v = Array.unsafe_get a i in
1421- tolist (i - 1)
1427+ tolist_aux a f (i - 1)
14221428 (match f v with
14231429 | Some v -> v :: res
1424- | None -> res) in
1425- tolist (Array.length a - 1) []
1430+ | None -> res)
1431+
1432+ let to_list_map f a =
1433+ tolist_aux a f (Array.length a - 1) []
1434+
1435+ let to_list_map_acc f a acc =
1436+ tolist_aux a f (Array.length a - 1) acc
14261437
14271438
14281439(* TODO: What would happen if [f] raise, memory leak? *)
@@ -2262,7 +2273,19 @@ let suites =
22622273 Ext_array.of_list_map succ [] =~ [||];
22632274 Ext_array.of_list_map succ [1] =~ [|2|];
22642275 Ext_array.of_list_map succ [1;2;3] =~ [|2;3;4|];
2265- end
2276+ end;
2277+ __LOC__ >:: begin fun _ ->
2278+ Ext_array.to_list_map_acc
2279+ (fun x -> if x mod 2 = 0 then Some x else None )
2280+ [|1;2;3;4;5;6|] [1;2;3]
2281+ =~ [2;4;6;1;2;3]
2282+ end;
2283+ __LOC__ >:: begin fun _ ->
2284+ Ext_array.to_list_map_acc
2285+ (fun x -> if x mod 2 = 0 then Some x else None )
2286+ [|1;2;3;4;5;6|] []
2287+ =~ [2;4;6]
2288+ end;
22662289 ]
22672290end
22682291module Ounit_tests_util
@@ -3539,7 +3562,10 @@ val commonjs : string
35393562val amdjs : string
35403563val goog : string
35413564val es6 : string
3565+ val es6_global : string
3566+ val amdjs_global : string
35423567val unused_attribute : string
3568+ val dash_nostdlib : string
35433569end = struct
35443570#1 "literals.ml"
35453571(* Copyright (C) 2015-2016 Bloomberg Finance L.P.
@@ -3639,8 +3665,10 @@ let commonjs = "commonjs"
36393665let amdjs = "amdjs"
36403666let goog = "goog"
36413667let es6 = "es6"
3642-
3668+ let es6_global = "es6-global"
3669+ let amdjs_global = "amdjs-global"
36433670let unused_attribute = "Unused attribute "
3671+ let dash_nostdlib = "-nostdlib"
36443672end
36453673module Ounit_cmd_util : sig
36463674#1 "ounit_cmd_util.mli"
0 commit comments