87 lines
1.3 KiB
JavaScript
87 lines
1.3 KiB
JavaScript
|
|
|
|
|
|
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;
|
|
}
|
|
}
|
|
|
|
export {
|
|
nullable_to_opt ,
|
|
undefined_to_opt ,
|
|
null_to_opt ,
|
|
valFromOption ,
|
|
some ,
|
|
isNested ,
|
|
option_get ,
|
|
option_unwrap ,
|
|
}
|
|
/* No side effect */
|