forked from rescript-lang/rescript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcaml_option.js
84 lines (74 loc) · 1.5 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
'use strict';
function isNested(x) {
return x.BS_PRIVATE_NESTED_SOME_NONE !== undefined;
}
function some(x) {
if (x === undefined) {
return {
BS_PRIVATE_NESTED_SOME_NONE: 0
};
} else if (x !== null && x.BS_PRIVATE_NESTED_SOME_NONE !== undefined) {
return {
BS_PRIVATE_NESTED_SOME_NONE: x.BS_PRIVATE_NESTED_SOME_NONE + 1 | 0
};
} else {
return x;
}
}
function nullable_to_opt(x) {
if (x == null) {
return ;
} else {
return some(x);
}
}
function undefined_to_opt(x) {
if (x === undefined) {
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.BS_PRIVATE_NESTED_SOME_NONE !== undefined)) {
return x;
}
var depth = x.BS_PRIVATE_NESTED_SOME_NONE;
if (depth === 0) {
return ;
} else {
return {
BS_PRIVATE_NESTED_SOME_NONE: depth - 1 | 0
};
}
}
function option_get(x) {
if (x === undefined) {
return ;
} else {
return valFromOption(x);
}
}
function option_unwrap(x) {
if (x !== undefined) {
return x.VAL;
} else {
return x;
}
}
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.isNested = isNested;
exports.option_get = option_get;
exports.option_unwrap = option_unwrap;
/* No side effect */