-
Notifications
You must be signed in to change notification settings - Fork 464
/
Copy pathBelt_MutableStack.js
130 lines (110 loc) · 1.97 KB
/
Belt_MutableStack.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
'use strict';
let Primitive_option = require("./Primitive_option.js");
function make() {
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) {
let x = s.root;
if (x !== undefined) {
return x.head;
}
}
function top(s) {
let x = s.root;
if (x !== undefined) {
return Primitive_option.some(x.head);
}
}
function isEmpty(s) {
return s.root === undefined;
}
function popUndefined(s) {
let x = s.root;
if (x !== undefined) {
s.root = x.tail;
return x.head;
}
}
function pop(s) {
let x = s.root;
if (x !== undefined) {
s.root = x.tail;
return Primitive_option.some(x.head);
}
}
function size(s) {
let x = s.root;
if (x !== undefined) {
let _x = x;
let _acc = 0;
while (true) {
let acc = _acc;
let x$1 = _x;
let 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 forEach(s, f) {
let _s = s.root;
while (true) {
let s$1 = _s;
if (s$1 === undefined) {
return;
}
f(s$1.head);
_s = s$1.tail;
continue;
};
}
function dynamicPopIter(s, f) {
while (true) {
let match = s.root;
if (match === undefined) {
return;
}
s.root = match.tail;
f(match.head);
continue;
};
}
let forEachU = forEach;
let dynamicPopIterU = dynamicPopIter;
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 */