time-to-botec/squiggle/node_modules/@rescript/std/lib/js/belt_MutableStack.js

136 lines
2.1 KiB
JavaScript
Raw Normal View History

'use strict';
var Curry = require("./curry.js");
var Caml_option = require("./caml_option.js");
function make(param) {
return {
root: undefined
};
}
function clear(s) {
s.root = undefined;
}
function copy(s) {
return {
root: s.root
};
}
function push(s, x) {
s.root = {
head: x,
tail: s.root
};
}
function topUndefined(s) {
var x = s.root;
if (x !== undefined) {
return x.head;
}
}
function top(s) {
var x = s.root;
if (x !== undefined) {
return Caml_option.some(x.head);
}
}
function isEmpty(s) {
return s.root === undefined;
}
function popUndefined(s) {
var x = s.root;
if (x !== undefined) {
s.root = x.tail;
return x.head;
}
}
function pop(s) {
var x = s.root;
if (x !== undefined) {
s.root = x.tail;
return Caml_option.some(x.head);
}
}
function size(s) {
var x = s.root;
if (x !== undefined) {
var _x = x;
var _acc = 0;
while(true) {
var acc = _acc;
var x$1 = _x;
var x$2 = x$1.tail;
if (x$2 === undefined) {
return acc + 1 | 0;
}
_acc = acc + 1 | 0;
_x = x$2;
continue ;
};
} else {
return 0;
}
}
function forEachU(s, f) {
var _s = s.root;
while(true) {
var s$1 = _s;
if (s$1 === undefined) {
return ;
}
f(s$1.head);
_s = s$1.tail;
continue ;
};
}
function forEach(s, f) {
forEachU(s, Curry.__1(f));
}
function dynamicPopIterU(s, f) {
while(true) {
var match = s.root;
if (match === undefined) {
return ;
}
s.root = match.tail;
f(match.head);
continue ;
};
}
function dynamicPopIter(s, f) {
dynamicPopIterU(s, Curry.__1(f));
}
exports.make = make;
exports.clear = clear;
exports.copy = copy;
exports.push = push;
exports.popUndefined = popUndefined;
exports.pop = pop;
exports.topUndefined = topUndefined;
exports.top = top;
exports.isEmpty = isEmpty;
exports.size = size;
exports.forEachU = forEachU;
exports.forEach = forEach;
exports.dynamicPopIterU = dynamicPopIterU;
exports.dynamicPopIter = dynamicPopIter;
/* No side effect */