forked from rescript-lang/rescript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcaml_option.js
89 lines (79 loc) · 1.45 KB
/
caml_option.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
'use strict';
var undefinedHeader = [];
function some(x) {
if (x === void 0) {
var block = /* tuple */[
undefinedHeader,
0
];
block.tag = 256;
return block;
}
if (!(x !== null && x[0] === undefinedHeader)) {
return x;
}
var nid = x[1] + 1 | 0;
var block$1 = /* tuple */[
undefinedHeader,
nid
];
block$1.tag = 256;
return block$1;
}
function nullable_to_opt(x) {
if (x === null || x === void 0) {
return ;
} else {
return some(x);
}
}
function undefined_to_opt(x) {
if (x === void 0) {
return ;
} else {
return some(x);
}
}
function null_to_opt(x) {
if (x === null) {
return ;
} else {
return some(x);
}
}
function valFromOption(x) {
if (!(x !== null && x[0] === undefinedHeader)) {
return x;
}
var depth = x[1];
if (depth === 0) {
return ;
} else {
return /* tuple */[
undefinedHeader,
depth - 1 | 0
];
}
}
function option_get(x) {
if (x === void 0) {
return ;
} else {
return valFromOption(x);
}
}
function option_get_unwrap(x) {
if (x === void 0) {
return ;
} else {
return valFromOption(x)[1];
}
}
exports.nullable_to_opt = nullable_to_opt;
exports.undefined_to_opt = undefined_to_opt;
exports.null_to_opt = null_to_opt;
exports.valFromOption = valFromOption;
exports.some = some;
exports.option_get = option_get;
exports.option_get_unwrap = option_get_unwrap;
/* No side effect */