Skip to content

Commit 3fda60e

Browse files
committed
tweak
1 parent b3a4103 commit 3fda60e

File tree

8 files changed

+89
-7
lines changed

8 files changed

+89
-7
lines changed

Diff for: jscomp/bin/bsppx.ml

+43-2
Original file line numberDiff line numberDiff line change
@@ -5876,6 +5876,12 @@ val fold_right : ('a -> 'b -> 'b) -> 'a list -> 'b -> 'b
58765876

58775877
val fold_right2 : ('a -> 'b -> 'c -> 'c) -> 'a list -> 'b list -> 'c -> 'c
58785878

5879+
val map2 :
5880+
('a -> 'b -> 'c) ->
5881+
'a list ->
5882+
'b list ->
5883+
'c list
5884+
58795885
val fold_left_with_offset :
58805886
(int -> 'acc -> 'a -> 'acc) ->
58815887
int ->
@@ -6146,6 +6152,41 @@ let rec fold_right2 f l r acc =
61466152
f a0 b0 (f a1 b1 (f a2 b2 (f a3 b3 (f a4 b4 (fold_right2 f arest brest acc)))))
61476153
| _, _ -> invalid_arg "Ext_list.fold_right2"
61486154

6155+
let rec map2 f l r =
6156+
match l,r with
6157+
| [],[] -> []
6158+
| [a0],[b0] -> [f a0 b0]
6159+
| [a0;a1],[b0;b1] ->
6160+
let c0 = f a0 b0 in
6161+
let c1 = f a1 b1 in
6162+
[c0; c1]
6163+
| [a0;a1;a2],[b0;b1;b2] ->
6164+
let c0 = f a0 b0 in
6165+
let c1 = f a1 b1 in
6166+
let c2 = f a2 b2 in
6167+
[c0;c1;c2]
6168+
| [a0;a1;a2;a3],[b0;b1;b2;b3] ->
6169+
let c0 = f a0 b0 in
6170+
let c1 = f a1 b1 in
6171+
let c2 = f a2 b2 in
6172+
let c3 = f a3 b3 in
6173+
[c0;c1;c2;c3]
6174+
| [a0;a1;a2;a3;a4], [b0;b1;b2;b3;b4] ->
6175+
let c0 = f a0 b0 in
6176+
let c1 = f a1 b1 in
6177+
let c2 = f a2 b2 in
6178+
let c3 = f a3 b3 in
6179+
let c4 = f a4 b4 in
6180+
[c0;c1;c2;c3;c4]
6181+
| a0::a1::a2::a3::a4::arest, b0::b1::b2::b3::b4::brest ->
6182+
let c0 = f a0 b0 in
6183+
let c1 = f a1 b1 in
6184+
let c2 = f a2 b2 in
6185+
let c3 = f a3 b3 in
6186+
let c4 = f a4 b4 in
6187+
c0::c1::c2::c3::c4::map2 f arest brest
6188+
| _, _ -> invalid_arg "Ext_list.map2"
6189+
61496190
let rec fold_left_with_offset f i accu l =
61506191
match l with
61516192
| [] -> accu
@@ -9159,7 +9200,7 @@ let from_labels ~loc arity labels
91599200
let result_type =
91609201
Ast_comb.to_js_type loc
91619202
(Typ.object_ ~loc
9162-
(List.map2 (fun x y -> x.Asttypes.txt ,[], y) labels tyvars) Closed)
9203+
(Ext_list.map2 (fun x y -> x.Asttypes.txt ,[], y) labels tyvars) Closed)
91639204
in
91649205
Ext_list.fold_right2
91659206
(fun {Asttypes.loc ; txt = label }
@@ -16822,7 +16863,7 @@ let ocaml_obj_as_js_object
1682216863
~pval_prim:(Ast_external_attributes.pval_prim_of_labels labels)
1682316864
(fun e ->
1682416865
Exp.apply ~loc e
16825-
(List.map2 (fun l expr -> l.Asttypes.txt, expr) labels exprs) )
16866+
(Ext_list.map2 (fun l expr -> l.Asttypes.txt, expr) labels exprs) )
1682616867
~pval_type
1682716868

1682816869

Diff for: jscomp/core/js_exp_make.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ let make_block ?comment tag tag_info es mutable_flag : t =
130130
List.mapi (fun i (e : t) -> merge_outer_comment des.(i) e) es
131131
(* TODO: may overriden its previous comments *)
132132
| Blk_module (Some des)
133-
-> List.map2 merge_outer_comment
133+
-> Ext_list.map2 merge_outer_comment
134134
des es
135135
| _ -> es
136136
in

Diff for: jscomp/core/lam_bounded_vars.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ let rewrite (map : _ Ident_hashtbl.t)
8888
| Lletrec(bindings, body) ->
8989
(*order matters see GPR #405*)
9090
let vars = Ext_list.map (fun (k, _) -> rebind k) bindings in
91-
let bindings = List.map2 (fun var (_,l) -> var, aux l) vars bindings in
91+
let bindings = Ext_list.map2 (fun var (_,l) -> var, aux l) vars bindings in
9292
let body = aux body in
9393
Lam.letrec bindings body
9494
| Lfunction{arity; function_kind; params; body} ->

Diff for: jscomp/core/lam_compile.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1181,7 +1181,7 @@ and
11811181
match Lam_compile_context.find_exn i cxt with
11821182
| {exit_id; args ; order_id} ->
11831183
let args_code =
1184-
(Js_output.concat @@ List.map2 (
1184+
(Js_output.concat @@ Ext_list.map2 (
11851185
fun (x : Lam.t) (arg : Ident.t) ->
11861186
match x with
11871187
| Lvar id ->

Diff for: jscomp/ext/ext_list.ml

+35
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,41 @@ let rec fold_right2 f l r acc =
129129
f a0 b0 (f a1 b1 (f a2 b2 (f a3 b3 (f a4 b4 (fold_right2 f arest brest acc)))))
130130
| _, _ -> invalid_arg "Ext_list.fold_right2"
131131

132+
let rec map2 f l r =
133+
match l,r with
134+
| [],[] -> []
135+
| [a0],[b0] -> [f a0 b0]
136+
| [a0;a1],[b0;b1] ->
137+
let c0 = f a0 b0 in
138+
let c1 = f a1 b1 in
139+
[c0; c1]
140+
| [a0;a1;a2],[b0;b1;b2] ->
141+
let c0 = f a0 b0 in
142+
let c1 = f a1 b1 in
143+
let c2 = f a2 b2 in
144+
[c0;c1;c2]
145+
| [a0;a1;a2;a3],[b0;b1;b2;b3] ->
146+
let c0 = f a0 b0 in
147+
let c1 = f a1 b1 in
148+
let c2 = f a2 b2 in
149+
let c3 = f a3 b3 in
150+
[c0;c1;c2;c3]
151+
| [a0;a1;a2;a3;a4], [b0;b1;b2;b3;b4] ->
152+
let c0 = f a0 b0 in
153+
let c1 = f a1 b1 in
154+
let c2 = f a2 b2 in
155+
let c3 = f a3 b3 in
156+
let c4 = f a4 b4 in
157+
[c0;c1;c2;c3;c4]
158+
| a0::a1::a2::a3::a4::arest, b0::b1::b2::b3::b4::brest ->
159+
let c0 = f a0 b0 in
160+
let c1 = f a1 b1 in
161+
let c2 = f a2 b2 in
162+
let c3 = f a3 b3 in
163+
let c4 = f a4 b4 in
164+
c0::c1::c2::c3::c4::map2 f arest brest
165+
| _, _ -> invalid_arg "Ext_list.map2"
166+
132167
let rec fold_left_with_offset f i accu l =
133168
match l with
134169
| [] -> accu

Diff for: jscomp/ext/ext_list.mli

+6
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ val fold_right : ('a -> 'b -> 'b) -> 'a list -> 'b -> 'b
3333

3434
val fold_right2 : ('a -> 'b -> 'c -> 'c) -> 'a list -> 'b list -> 'c -> 'c
3535

36+
val map2 :
37+
('a -> 'b -> 'c) ->
38+
'a list ->
39+
'b list ->
40+
'c list
41+
3642
val fold_left_with_offset :
3743
(int -> 'acc -> 'a -> 'acc) ->
3844
int ->

Diff for: jscomp/syntax/ast_core_type.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ let from_labels ~loc arity labels
122122
let result_type =
123123
Ast_comb.to_js_type loc
124124
(Typ.object_ ~loc
125-
(List.map2 (fun x y -> x.Asttypes.txt ,[], y) labels tyvars) Closed)
125+
(Ext_list.map2 (fun x y -> x.Asttypes.txt ,[], y) labels tyvars) Closed)
126126
in
127127
Ext_list.fold_right2
128128
(fun {Asttypes.loc ; txt = label }

Diff for: jscomp/syntax/ast_util.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,7 @@ let ocaml_obj_as_js_object
607607
~pval_prim:(Ast_external_attributes.pval_prim_of_labels labels)
608608
(fun e ->
609609
Exp.apply ~loc e
610-
(List.map2 (fun l expr -> l.Asttypes.txt, expr) labels exprs) )
610+
(Ext_list.map2 (fun l expr -> l.Asttypes.txt, expr) labels exprs) )
611611
~pval_type
612612

613613

0 commit comments

Comments
 (0)