Skip to content

Commit ef8e334

Browse files
authored
Merge pull request #1062 from chenglou/fix-mli
Expose Js_(null|undefined|null_undefined).from_opt in mli
2 parents a01e0f4 + aa4a0c6 commit ef8e334

File tree

6 files changed

+46
-13
lines changed

6 files changed

+46
-13
lines changed

jscomp/others/js_null_undefined.mli

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
(* Copyright (C) 2015-2016 Bloomberg Finance L.P.
2-
*
2+
*
33
* This program is free software: you can redistribute it and/or modify
44
* it under the terms of the GNU Lesser General Public License as published by
55
* the Free Software Foundation, either version 3 of the License, or
@@ -17,7 +17,7 @@
1717
* but WITHOUT ANY WARRANTY; without even the implied warranty of
1818
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1919
* GNU Lesser General Public License for more details.
20-
*
20+
*
2121
* You should have received a copy of the GNU Lesser General Public License
2222
* along with this program; if not, write to the Free Software
2323
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
@@ -28,8 +28,9 @@ external return : 'a -> 'a t = "%identity"
2828
external test : 'a t -> bool = "js_is_nil_undef"
2929
external empty : 'a t = "undefined" [@@bs.val]
3030

31-
(** we did not add [bind] yet, since the return value is
31+
(** we did not add [bind] yet, since the return value is
3232
ambiguous and [to_opt] depends on {!Js_primitive}
3333
*)
3434
val bind : 'a t -> ('a -> 'b [@bs]) -> 'b t
3535
val iter : 'a t -> ('a -> unit [@bs]) -> unit
36+
val from_opt : 'a option -> 'a t

jscomp/runtime/js_null.mli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,4 @@ external empty : 'a t = "null" [@@bs.val]
3030

3131
val bind : 'a t -> ('a -> 'b [@bs]) -> 'b t
3232
val iter : 'a t -> ('a -> unit [@bs]) -> unit
33+
val from_opt : 'a option -> 'a t

jscomp/runtime/js_undefined.mli

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
(* Copyright (C) 2015-2016 Bloomberg Finance L.P.
2-
*
2+
*
33
* This program is free software: you can redistribute it and/or modify
44
* it under the terms of the GNU Lesser General Public License as published by
55
* the Free Software Foundation, either version 3 of the License, or
@@ -17,17 +17,18 @@
1717
* but WITHOUT ANY WARRANTY; without even the implied warranty of
1818
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1919
* GNU Lesser General Public License for more details.
20-
*
20+
*
2121
* You should have received a copy of the GNU Lesser General Public License
2222
* along with this program; if not, write to the Free Software
2323
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
2424

25-
type + 'a t = 'a Js.undefined
25+
type + 'a t = 'a Js.undefined
2626
external to_opt : 'a t -> 'a option = "js_from_def"
2727
external return : 'a -> 'a t = "%identity"
2828
external test : 'a t -> bool = "js_is_undef"
29-
external empty : 'a t = "undefined"
29+
external empty : 'a t = "undefined"
3030
[@@bs.val]
3131

3232
val bind : 'a t -> ('a -> 'b [@bs]) -> 'b t
3333
val iter : 'a t -> ('a -> unit [@bs]) -> unit
34+
val from_opt : 'a option -> 'a t

lib/js/js_null.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,16 @@ function iter(x, f) {
1919
}
2020
}
2121

22-
exports.bind = bind;
23-
exports.iter = iter;
22+
function from_opt(x) {
23+
if (x) {
24+
return x[0];
25+
}
26+
else {
27+
return null;
28+
}
29+
}
30+
31+
exports.bind = bind;
32+
exports.iter = iter;
33+
exports.from_opt = from_opt;
2434
/* No side effect */

lib/js/js_null_undefined.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,16 @@ function iter(x, f) {
2020
}
2121
}
2222

23-
exports.bind = bind;
24-
exports.iter = iter;
23+
function from_opt(x) {
24+
if (x) {
25+
return x[0];
26+
}
27+
else {
28+
return undefined;
29+
}
30+
}
31+
32+
exports.bind = bind;
33+
exports.iter = iter;
34+
exports.from_opt = from_opt;
2535
/* No side effect */

lib/js/js_undefined.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,16 @@ function iter(x, f) {
1919
}
2020
}
2121

22-
exports.bind = bind;
23-
exports.iter = iter;
22+
function from_opt(x) {
23+
if (x) {
24+
return x[0];
25+
}
26+
else {
27+
return undefined;
28+
}
29+
}
30+
31+
exports.bind = bind;
32+
exports.iter = iter;
33+
exports.from_opt = from_opt;
2434
/* No side effect */

0 commit comments

Comments
 (0)