forked from rescript-lang/rescript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbelt_MutableStack.js
142 lines (126 loc) · 2.28 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
131
132
133
134
135
136
137
138
139
140
141
142
'use strict';
var Curry = require("./curry.js");
function make() {
return {
root: null
};
}
function clear(s) {
s.root = null;
return /* () */0;
}
function copy(s) {
return {
root: s.root
};
}
function push(s, x) {
s.root = {
head: x,
tail: s.root
};
return /* () */0;
}
function topUndefined(s) {
var match = s.root;
if (match !== null) {
return match.head;
} else {
return undefined;
}
}
function top(s) {
var match = s.root;
if (match !== null) {
return /* Some */[match.head];
} else {
return /* None */0;
}
}
function isEmpty(s) {
return s.root === null;
}
function popUndefined(s) {
var match = s.root;
if (match !== null) {
s.root = match.tail;
return match.head;
} else {
return undefined;
}
}
function pop(s) {
var match = s.root;
if (match !== null) {
s.root = match.tail;
return /* Some */[match.head];
} else {
return /* None */0;
}
}
function size(s) {
var match = s.root;
if (match !== null) {
var _x = match;
var _acc = 0;
while(true) {
var acc = _acc;
var x = _x;
var match$1 = x.tail;
if (match$1 !== null) {
_acc = acc + 1 | 0;
_x = match$1;
continue ;
} else {
return acc + 1 | 0;
}
};
} else {
return 0;
}
}
function forEachU(s, f) {
var _s = s.root;
var f$1 = f;
while(true) {
var s$1 = _s;
if (s$1 !== null) {
f$1(s$1.head);
_s = s$1.tail;
continue ;
} else {
return /* () */0;
}
};
}
function forEach(s, f) {
return forEachU(s, Curry.__1(f));
}
function dynamicPopIterU(s, f) {
var cursor = s.root;
while(cursor !== null) {
var v = cursor;
s.root = v.tail;
f(v.head);
cursor = s.root;
};
return /* () */0;
}
function dynamicPopIter(s, f) {
return 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 */