@grain/stdlib 0.6.6 → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +67 -0
- package/LICENSE +1 -1
- package/README.md +2 -2
- package/array.gr +55 -7
- package/array.md +606 -560
- package/bigint.md +228 -228
- package/buffer.gr +85 -53
- package/buffer.md +442 -319
- package/bytes.gr +112 -35
- package/bytes.md +299 -219
- package/char.gr +201 -99
- package/char.md +447 -120
- package/exception.gr +11 -11
- package/exception.md +29 -4
- package/float32.gr +327 -3
- package/float32.md +698 -111
- package/float64.gr +320 -3
- package/float64.md +698 -111
- package/fs.gr +1082 -0
- package/fs.md +630 -0
- package/hash.gr +142 -88
- package/hash.md +105 -17
- package/int16.md +178 -178
- package/int32.gr +26 -5
- package/int32.md +266 -231
- package/int64.gr +27 -2
- package/int64.md +266 -231
- package/int8.md +178 -178
- package/json.gr +366 -51
- package/json.md +431 -15
- package/list.gr +328 -31
- package/list.md +759 -336
- package/map.gr +20 -12
- package/map.md +266 -260
- package/marshal.gr +41 -40
- package/marshal.md +14 -14
- package/number.gr +278 -35
- package/number.md +688 -269
- package/option.md +162 -162
- package/package.json +5 -3
- package/path.gr +48 -0
- package/path.md +180 -89
- package/pervasives.gr +2 -2
- package/pervasives.md +275 -275
- package/priorityqueue.gr +7 -7
- package/priorityqueue.md +131 -131
- package/queue.gr +183 -29
- package/queue.md +404 -148
- package/random.md +43 -43
- package/range.gr +4 -4
- package/range.md +42 -42
- package/rational.md +123 -123
- package/regex.gr +52 -51
- package/regex.md +102 -102
- package/result.md +118 -118
- package/runtime/atof/common.md +39 -39
- package/runtime/atof/decimal.gr +6 -6
- package/runtime/atof/decimal.md +14 -14
- package/runtime/atof/lemire.gr +5 -5
- package/runtime/atof/lemire.md +1 -1
- package/runtime/atof/parse.gr +16 -16
- package/runtime/atof/parse.md +2 -2
- package/runtime/atof/slow.md +1 -1
- package/runtime/atof/table.md +2 -2
- package/runtime/atoi/parse.gr +3 -3
- package/runtime/atoi/parse.md +1 -1
- package/runtime/bigint.gr +15 -47
- package/runtime/bigint.md +54 -60
- package/runtime/compare.gr +2 -2
- package/runtime/compare.md +8 -8
- package/runtime/dataStructures.md +211 -211
- package/runtime/debugPrint.gr +4 -1
- package/runtime/debugPrint.md +9 -9
- package/runtime/equal.gr +99 -77
- package/runtime/equal.md +8 -8
- package/runtime/exception.gr +62 -82
- package/runtime/exception.md +62 -11
- package/runtime/gc.gr +39 -45
- package/runtime/gc.md +4 -4
- package/runtime/malloc.gr +7 -7
- package/runtime/malloc.md +13 -13
- package/runtime/math/kernel/cos.gr +70 -0
- package/runtime/math/kernel/cos.md +14 -0
- package/runtime/math/kernel/sin.gr +65 -0
- package/runtime/math/kernel/sin.md +14 -0
- package/runtime/math/kernel/tan.gr +136 -0
- package/runtime/math/kernel/tan.md +14 -0
- package/runtime/math/rempio2.gr +244 -0
- package/runtime/math/rempio2.md +14 -0
- package/runtime/math/trig.gr +130 -0
- package/runtime/math/trig.md +28 -0
- package/runtime/math/umuldi.gr +26 -0
- package/runtime/math/umuldi.md +14 -0
- package/runtime/numberUtils.gr +29 -29
- package/runtime/numberUtils.md +12 -12
- package/runtime/numbers.gr +373 -381
- package/runtime/numbers.md +348 -342
- package/runtime/string.gr +37 -105
- package/runtime/string.md +20 -26
- package/runtime/unsafe/constants.md +24 -24
- package/runtime/unsafe/conv.md +19 -19
- package/runtime/unsafe/memory.gr +24 -20
- package/runtime/unsafe/memory.md +27 -7
- package/runtime/unsafe/offsets.gr +36 -0
- package/runtime/unsafe/offsets.md +88 -0
- package/runtime/unsafe/panic.gr +28 -0
- package/runtime/unsafe/panic.md +14 -0
- package/runtime/unsafe/tags.md +32 -32
- package/runtime/unsafe/wasmf32.md +28 -28
- package/runtime/unsafe/wasmf64.md +28 -28
- package/runtime/unsafe/wasmi32.md +47 -47
- package/runtime/unsafe/wasmi64.md +50 -50
- package/runtime/utf8.gr +189 -0
- package/runtime/utf8.md +117 -0
- package/runtime/wasi.gr +4 -2
- package/runtime/wasi.md +147 -147
- package/set.gr +18 -11
- package/set.md +253 -247
- package/stack.gr +171 -2
- package/stack.md +371 -89
- package/string.gr +352 -557
- package/string.md +298 -255
- package/uint16.md +170 -170
- package/uint32.gr +25 -4
- package/uint32.md +249 -214
- package/uint64.gr +25 -5
- package/uint64.md +249 -214
- package/uint8.md +170 -170
- package/uri.gr +57 -53
- package/uri.md +88 -89
- package/wasi/file.gr +67 -59
- package/wasi/file.md +308 -308
- package/wasi/process.md +26 -26
- package/wasi/random.md +12 -12
- package/wasi/time.md +16 -16
- package/runtime/utils/printing.gr +0 -60
- package/runtime/utils/printing.md +0 -26
package/stack.md
CHANGED
|
@@ -41,25 +41,25 @@ No other changes yet.
|
|
|
41
41
|
</details>
|
|
42
42
|
|
|
43
43
|
```grain
|
|
44
|
-
make
|
|
44
|
+
make: (?size: Number) => Stack<a>
|
|
45
45
|
```
|
|
46
46
|
|
|
47
47
|
Creates a new stack with an initial storage of the given size. As values are
|
|
48
48
|
added or removed, the internal storage may grow or shrink. Generally, you
|
|
49
|
-
won’t need to care about the storage size of your
|
|
49
|
+
won’t need to care about the storage size of your stack and can use the
|
|
50
50
|
default size.
|
|
51
51
|
|
|
52
52
|
Parameters:
|
|
53
53
|
|
|
54
|
-
|param|type|description|
|
|
55
|
-
|
|
56
|
-
|
|
54
|
+
| param | type | description |
|
|
55
|
+
| ------- | -------- | ------------------------------------- |
|
|
56
|
+
| `?size` | `Number` | The initial storage size of the stack |
|
|
57
57
|
|
|
58
58
|
Returns:
|
|
59
59
|
|
|
60
|
-
|type|description|
|
|
61
|
-
|
|
62
|
-
|
|
60
|
+
| type | description |
|
|
61
|
+
| ---------- | -------------- |
|
|
62
|
+
| `Stack<a>` | An empty stack |
|
|
63
63
|
|
|
64
64
|
### Stack.**isEmpty**
|
|
65
65
|
|
|
@@ -69,22 +69,22 @@ No other changes yet.
|
|
|
69
69
|
</details>
|
|
70
70
|
|
|
71
71
|
```grain
|
|
72
|
-
isEmpty
|
|
72
|
+
isEmpty: (stack: Stack<a>) => Bool
|
|
73
73
|
```
|
|
74
74
|
|
|
75
75
|
Checks if the given stack contains no items.
|
|
76
76
|
|
|
77
77
|
Parameters:
|
|
78
78
|
|
|
79
|
-
|param|type|description|
|
|
80
|
-
|
|
81
|
-
|
|
79
|
+
| param | type | description |
|
|
80
|
+
| ------- | ---------- | ------------------ |
|
|
81
|
+
| `stack` | `Stack<a>` | The stack to check |
|
|
82
82
|
|
|
83
83
|
Returns:
|
|
84
84
|
|
|
85
|
-
|type|description|
|
|
86
|
-
|
|
87
|
-
|
|
85
|
+
| type | description |
|
|
86
|
+
| ------ | ----------------------------------------------------- |
|
|
87
|
+
| `Bool` | `true` if the stack has no items or `false` otherwise |
|
|
88
88
|
|
|
89
89
|
### Stack.**size**
|
|
90
90
|
|
|
@@ -94,22 +94,22 @@ No other changes yet.
|
|
|
94
94
|
</details>
|
|
95
95
|
|
|
96
96
|
```grain
|
|
97
|
-
size
|
|
97
|
+
size: (stack: Stack<a>) => Number
|
|
98
98
|
```
|
|
99
99
|
|
|
100
100
|
Computes the size of the input stack.
|
|
101
101
|
|
|
102
102
|
Parameters:
|
|
103
103
|
|
|
104
|
-
|param|type|description|
|
|
105
|
-
|
|
106
|
-
|
|
104
|
+
| param | type | description |
|
|
105
|
+
| ------- | ---------- | -------------------- |
|
|
106
|
+
| `stack` | `Stack<a>` | The stack to inspect |
|
|
107
107
|
|
|
108
108
|
Returns:
|
|
109
109
|
|
|
110
|
-
|type|description|
|
|
111
|
-
|
|
112
|
-
|
|
110
|
+
| type | description |
|
|
111
|
+
| -------- | ----------------------------------- |
|
|
112
|
+
| `Number` | The count of the items in the stack |
|
|
113
113
|
|
|
114
114
|
### Stack.**peek**
|
|
115
115
|
|
|
@@ -119,22 +119,22 @@ No other changes yet.
|
|
|
119
119
|
</details>
|
|
120
120
|
|
|
121
121
|
```grain
|
|
122
|
-
peek
|
|
122
|
+
peek: (stack: Stack<a>) => Option<a>
|
|
123
123
|
```
|
|
124
124
|
|
|
125
125
|
Provides the value at the top of the stack, if it exists.
|
|
126
126
|
|
|
127
127
|
Parameters:
|
|
128
128
|
|
|
129
|
-
|param|type|description|
|
|
130
|
-
|
|
131
|
-
|
|
129
|
+
| param | type | description |
|
|
130
|
+
| ------- | ---------- | -------------------- |
|
|
131
|
+
| `stack` | `Stack<a>` | The stack to inspect |
|
|
132
132
|
|
|
133
133
|
Returns:
|
|
134
134
|
|
|
135
|
-
|type|description|
|
|
136
|
-
|
|
137
|
-
|
|
135
|
+
| type | description |
|
|
136
|
+
| ----------- | ------------------------------------------------------------------------------- |
|
|
137
|
+
| `Option<a>` | `Some(value)` containing the value at the top of the stack or `None` otherwise. |
|
|
138
138
|
|
|
139
139
|
### Stack.**push**
|
|
140
140
|
|
|
@@ -144,17 +144,17 @@ No other changes yet.
|
|
|
144
144
|
</details>
|
|
145
145
|
|
|
146
146
|
```grain
|
|
147
|
-
push
|
|
147
|
+
push: (value: a, stack: Stack<a>) => Void
|
|
148
148
|
```
|
|
149
149
|
|
|
150
150
|
Adds a new item to the top of the stack.
|
|
151
151
|
|
|
152
152
|
Parameters:
|
|
153
153
|
|
|
154
|
-
|param|type|description|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
154
|
+
| param | type | description |
|
|
155
|
+
| ------- | ---------- | ----------------------- |
|
|
156
|
+
| `value` | `a` | The item to be added |
|
|
157
|
+
| `stack` | `Stack<a>` | The stack being updated |
|
|
158
158
|
|
|
159
159
|
### Stack.**pop**
|
|
160
160
|
|
|
@@ -164,22 +164,22 @@ No other changes yet.
|
|
|
164
164
|
</details>
|
|
165
165
|
|
|
166
166
|
```grain
|
|
167
|
-
pop
|
|
167
|
+
pop: (stack: Stack<a>) => Option<a>
|
|
168
168
|
```
|
|
169
169
|
|
|
170
170
|
Removes the item at the top of the stack.
|
|
171
171
|
|
|
172
172
|
Parameters:
|
|
173
173
|
|
|
174
|
-
|param|type|description|
|
|
175
|
-
|
|
176
|
-
|
|
174
|
+
| param | type | description |
|
|
175
|
+
| ------- | ---------- | ----------------------- |
|
|
176
|
+
| `stack` | `Stack<a>` | The stack being updated |
|
|
177
177
|
|
|
178
178
|
Returns:
|
|
179
179
|
|
|
180
|
-
|type|description|
|
|
181
|
-
|
|
182
|
-
|
|
180
|
+
| type | description |
|
|
181
|
+
| ----------- | ---------------------------------- |
|
|
182
|
+
| `Option<a>` | The element removed from the stack |
|
|
183
183
|
|
|
184
184
|
### Stack.**clear**
|
|
185
185
|
|
|
@@ -189,16 +189,16 @@ No other changes yet.
|
|
|
189
189
|
</details>
|
|
190
190
|
|
|
191
191
|
```grain
|
|
192
|
-
clear
|
|
192
|
+
clear: (stack: Stack<a>) => Void
|
|
193
193
|
```
|
|
194
194
|
|
|
195
195
|
Clears the stack by removing all of its elements
|
|
196
196
|
|
|
197
197
|
Parameters:
|
|
198
198
|
|
|
199
|
-
|param|type|description|
|
|
200
|
-
|
|
201
|
-
|
|
199
|
+
| param | type | description |
|
|
200
|
+
| ------- | ---------- | ------------------ |
|
|
201
|
+
| `stack` | `Stack<a>` | The stack to clear |
|
|
202
202
|
|
|
203
203
|
### Stack.**copy**
|
|
204
204
|
|
|
@@ -208,22 +208,160 @@ No other changes yet.
|
|
|
208
208
|
</details>
|
|
209
209
|
|
|
210
210
|
```grain
|
|
211
|
-
copy
|
|
211
|
+
copy: (stack: Stack<a>) => Stack<a>
|
|
212
212
|
```
|
|
213
213
|
|
|
214
214
|
Produces a shallow copy of the input stack.
|
|
215
215
|
|
|
216
216
|
Parameters:
|
|
217
217
|
|
|
218
|
-
|param|type|description|
|
|
219
|
-
|
|
220
|
-
|
|
218
|
+
| param | type | description |
|
|
219
|
+
| ------- | ---------- | ----------------- |
|
|
220
|
+
| `stack` | `Stack<a>` | The stack to copy |
|
|
221
221
|
|
|
222
222
|
Returns:
|
|
223
223
|
|
|
224
|
-
|type|description|
|
|
225
|
-
|
|
226
|
-
|
|
224
|
+
| type | description |
|
|
225
|
+
| ---------- | -------------------------------------------------- |
|
|
226
|
+
| `Stack<a>` | A new stack containing the elements from the input |
|
|
227
|
+
|
|
228
|
+
### Stack.**toList**
|
|
229
|
+
|
|
230
|
+
<details disabled>
|
|
231
|
+
<summary tabindex="-1">Added in <code>0.7.0</code></summary>
|
|
232
|
+
No other changes yet.
|
|
233
|
+
</details>
|
|
234
|
+
|
|
235
|
+
```grain
|
|
236
|
+
toList: (stack: Stack<a>) => List<a>
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
Creates a list containing the elements of a stack.
|
|
240
|
+
|
|
241
|
+
Parameters:
|
|
242
|
+
|
|
243
|
+
| param | type | description |
|
|
244
|
+
| ------- | ---------- | -------------------- |
|
|
245
|
+
| `stack` | `Stack<a>` | The stack to convert |
|
|
246
|
+
|
|
247
|
+
Returns:
|
|
248
|
+
|
|
249
|
+
| type | description |
|
|
250
|
+
| --------- | ---------------------------------- |
|
|
251
|
+
| `List<a>` | A list containing all stack values |
|
|
252
|
+
|
|
253
|
+
Examples:
|
|
254
|
+
|
|
255
|
+
```grain
|
|
256
|
+
let stack = Stack.make()
|
|
257
|
+
Stack.push(1, stack)
|
|
258
|
+
Stack.push(2, stack)
|
|
259
|
+
assert Stack.toList(stack) == [2, 1]
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
### Stack.**fromList**
|
|
263
|
+
|
|
264
|
+
<details disabled>
|
|
265
|
+
<summary tabindex="-1">Added in <code>0.7.0</code></summary>
|
|
266
|
+
No other changes yet.
|
|
267
|
+
</details>
|
|
268
|
+
|
|
269
|
+
```grain
|
|
270
|
+
fromList: (list: List<a>) => Stack<a>
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
Creates a stack from a list.
|
|
274
|
+
|
|
275
|
+
Parameters:
|
|
276
|
+
|
|
277
|
+
| param | type | description |
|
|
278
|
+
| ------ | --------- | ------------------- |
|
|
279
|
+
| `list` | `List<a>` | The list to convert |
|
|
280
|
+
|
|
281
|
+
Returns:
|
|
282
|
+
|
|
283
|
+
| type | description |
|
|
284
|
+
| ---------- | ---------------------------------- |
|
|
285
|
+
| `Stack<a>` | A stack containing all list values |
|
|
286
|
+
|
|
287
|
+
Examples:
|
|
288
|
+
|
|
289
|
+
```grain
|
|
290
|
+
let stack = Stack.fromList([3, 2, 1])
|
|
291
|
+
assert Stack.pop(stack) == Some(3)
|
|
292
|
+
assert Stack.pop(stack) == Some(2)
|
|
293
|
+
assert Stack.pop(stack) == Some(1)
|
|
294
|
+
assert Stack.pop(stack) == None
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
### Stack.**toArray**
|
|
298
|
+
|
|
299
|
+
<details disabled>
|
|
300
|
+
<summary tabindex="-1">Added in <code>0.7.0</code></summary>
|
|
301
|
+
No other changes yet.
|
|
302
|
+
</details>
|
|
303
|
+
|
|
304
|
+
```grain
|
|
305
|
+
toArray: (stack: Stack<a>) => Array<a>
|
|
306
|
+
```
|
|
307
|
+
|
|
308
|
+
Creates an array containing the elements of a stack.
|
|
309
|
+
|
|
310
|
+
Parameters:
|
|
311
|
+
|
|
312
|
+
| param | type | description |
|
|
313
|
+
| ------- | ---------- | -------------------- |
|
|
314
|
+
| `stack` | `Stack<a>` | The stack to convert |
|
|
315
|
+
|
|
316
|
+
Returns:
|
|
317
|
+
|
|
318
|
+
| type | description |
|
|
319
|
+
| ---------- | ------------------------------------ |
|
|
320
|
+
| `Array<a>` | An array containing all stack values |
|
|
321
|
+
|
|
322
|
+
Examples:
|
|
323
|
+
|
|
324
|
+
```grain
|
|
325
|
+
let stack = Stack.make()
|
|
326
|
+
Stack.push(1, stack)
|
|
327
|
+
Stack.push(2, stack)
|
|
328
|
+
assert Stack.toArray(stack) == [> 2, 1]
|
|
329
|
+
```
|
|
330
|
+
|
|
331
|
+
### Stack.**fromArray**
|
|
332
|
+
|
|
333
|
+
<details disabled>
|
|
334
|
+
<summary tabindex="-1">Added in <code>0.7.0</code></summary>
|
|
335
|
+
No other changes yet.
|
|
336
|
+
</details>
|
|
337
|
+
|
|
338
|
+
```grain
|
|
339
|
+
fromArray: (arr: Array<a>) => Stack<a>
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
Creates a stack from an array.
|
|
343
|
+
|
|
344
|
+
Parameters:
|
|
345
|
+
|
|
346
|
+
| param | type | description |
|
|
347
|
+
| ----- | ---------- | -------------------- |
|
|
348
|
+
| `arr` | `Array<a>` | The array to convert |
|
|
349
|
+
|
|
350
|
+
Returns:
|
|
351
|
+
|
|
352
|
+
| type | description |
|
|
353
|
+
| ---------- | ----------------------------------- |
|
|
354
|
+
| `Stack<a>` | A stack containing all array values |
|
|
355
|
+
|
|
356
|
+
Examples:
|
|
357
|
+
|
|
358
|
+
```grain
|
|
359
|
+
let s = Stack.fromArray([> 3, 2, 1])
|
|
360
|
+
assert Stack.pop(s) == Some(3)
|
|
361
|
+
assert Stack.pop(s) == Some(2)
|
|
362
|
+
assert Stack.pop(s) == Some(1)
|
|
363
|
+
assert Stack.pop(s) == None
|
|
364
|
+
```
|
|
227
365
|
|
|
228
366
|
## Stack.Immutable
|
|
229
367
|
|
|
@@ -260,7 +398,7 @@ Functions and constants included in the Stack.Immutable module.
|
|
|
260
398
|
</details>
|
|
261
399
|
|
|
262
400
|
```grain
|
|
263
|
-
empty
|
|
401
|
+
empty: ImmutableStack<a>
|
|
264
402
|
```
|
|
265
403
|
|
|
266
404
|
An empty stack.
|
|
@@ -280,22 +418,22 @@ An empty stack.
|
|
|
280
418
|
</details>
|
|
281
419
|
|
|
282
420
|
```grain
|
|
283
|
-
isEmpty
|
|
421
|
+
isEmpty: (stack: ImmutableStack<a>) => Bool
|
|
284
422
|
```
|
|
285
423
|
|
|
286
424
|
Checks if the given stack contains no items.
|
|
287
425
|
|
|
288
426
|
Parameters:
|
|
289
427
|
|
|
290
|
-
|param|type|description|
|
|
291
|
-
|
|
292
|
-
|
|
428
|
+
| param | type | description |
|
|
429
|
+
| ------- | ------------------- | ------------------ |
|
|
430
|
+
| `stack` | `ImmutableStack<a>` | The stack to check |
|
|
293
431
|
|
|
294
432
|
Returns:
|
|
295
433
|
|
|
296
|
-
|type|description|
|
|
297
|
-
|
|
298
|
-
|
|
434
|
+
| type | description |
|
|
435
|
+
| ------ | ----------------------------------------------------- |
|
|
436
|
+
| `Bool` | `true` if the stack has no items or `false` otherwise |
|
|
299
437
|
|
|
300
438
|
#### Stack.Immutable.**peek**
|
|
301
439
|
|
|
@@ -313,22 +451,22 @@ Returns:
|
|
|
313
451
|
</details>
|
|
314
452
|
|
|
315
453
|
```grain
|
|
316
|
-
peek
|
|
454
|
+
peek: (stack: ImmutableStack<a>) => Option<a>
|
|
317
455
|
```
|
|
318
456
|
|
|
319
457
|
Provides the value at the top of the stack, if it exists.
|
|
320
458
|
|
|
321
459
|
Parameters:
|
|
322
460
|
|
|
323
|
-
|param|type|description|
|
|
324
|
-
|
|
325
|
-
|
|
461
|
+
| param | type | description |
|
|
462
|
+
| ------- | ------------------- | -------------------- |
|
|
463
|
+
| `stack` | `ImmutableStack<a>` | The stack to inspect |
|
|
326
464
|
|
|
327
465
|
Returns:
|
|
328
466
|
|
|
329
|
-
|type|description|
|
|
330
|
-
|
|
331
|
-
|
|
467
|
+
| type | description |
|
|
468
|
+
| ----------- | ------------------------------------------------------------------------------- |
|
|
469
|
+
| `Option<a>` | `Some(value)` containing the value at the top of the stack or `None` otherwise. |
|
|
332
470
|
|
|
333
471
|
#### Stack.Immutable.**push**
|
|
334
472
|
|
|
@@ -345,23 +483,23 @@ Returns:
|
|
|
345
483
|
</details>
|
|
346
484
|
|
|
347
485
|
```grain
|
|
348
|
-
push
|
|
486
|
+
push: (value: a, stack: ImmutableStack<a>) => ImmutableStack<a>
|
|
349
487
|
```
|
|
350
488
|
|
|
351
489
|
Adds a new item to the top of the stack.
|
|
352
490
|
|
|
353
491
|
Parameters:
|
|
354
492
|
|
|
355
|
-
|param|type|description|
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
493
|
+
| param | type | description |
|
|
494
|
+
| ------- | ------------------- | ----------------------- |
|
|
495
|
+
| `value` | `a` | The item to be added |
|
|
496
|
+
| `stack` | `ImmutableStack<a>` | The stack being updated |
|
|
359
497
|
|
|
360
498
|
Returns:
|
|
361
499
|
|
|
362
|
-
|type|description|
|
|
363
|
-
|
|
364
|
-
|
|
500
|
+
| type | description |
|
|
501
|
+
| ------------------- | ------------------------------------------ |
|
|
502
|
+
| `ImmutableStack<a>` | A new stack with the item added to the end |
|
|
365
503
|
|
|
366
504
|
#### Stack.Immutable.**pop**
|
|
367
505
|
|
|
@@ -378,22 +516,22 @@ Returns:
|
|
|
378
516
|
</details>
|
|
379
517
|
|
|
380
518
|
```grain
|
|
381
|
-
pop
|
|
519
|
+
pop: (stack: ImmutableStack<a>) => ImmutableStack<a>
|
|
382
520
|
```
|
|
383
521
|
|
|
384
522
|
Removes the item at the top of the stack.
|
|
385
523
|
|
|
386
524
|
Parameters:
|
|
387
525
|
|
|
388
|
-
|param|type|description|
|
|
389
|
-
|
|
390
|
-
|
|
526
|
+
| param | type | description |
|
|
527
|
+
| ------- | ------------------- | ----------------------- |
|
|
528
|
+
| `stack` | `ImmutableStack<a>` | The stack being updated |
|
|
391
529
|
|
|
392
530
|
Returns:
|
|
393
531
|
|
|
394
|
-
|type|description|
|
|
395
|
-
|
|
396
|
-
|
|
532
|
+
| type | description |
|
|
533
|
+
| ------------------- | -------------------------------------- |
|
|
534
|
+
| `ImmutableStack<a>` | A new stack with the last item removed |
|
|
397
535
|
|
|
398
536
|
#### Stack.Immutable.**size**
|
|
399
537
|
|
|
@@ -410,20 +548,164 @@ Returns:
|
|
|
410
548
|
</details>
|
|
411
549
|
|
|
412
550
|
```grain
|
|
413
|
-
size
|
|
551
|
+
size: (stack: ImmutableStack<a>) => Number
|
|
414
552
|
```
|
|
415
553
|
|
|
416
554
|
Computes the size of the input stack.
|
|
417
555
|
|
|
418
556
|
Parameters:
|
|
419
557
|
|
|
420
|
-
|param|type|description|
|
|
421
|
-
|
|
422
|
-
|
|
558
|
+
| param | type | description |
|
|
559
|
+
| ------- | ------------------- | -------------------- |
|
|
560
|
+
| `stack` | `ImmutableStack<a>` | The stack to inspect |
|
|
423
561
|
|
|
424
562
|
Returns:
|
|
425
563
|
|
|
426
|
-
|type|description|
|
|
427
|
-
|
|
428
|
-
|
|
564
|
+
| type | description |
|
|
565
|
+
| -------- | ----------------------------------- |
|
|
566
|
+
| `Number` | The count of the items in the stack |
|
|
567
|
+
|
|
568
|
+
#### Stack.Immutable.**toList**
|
|
569
|
+
|
|
570
|
+
<details disabled>
|
|
571
|
+
<summary tabindex="-1">Added in <code>0.7.0</code></summary>
|
|
572
|
+
No other changes yet.
|
|
573
|
+
</details>
|
|
574
|
+
|
|
575
|
+
```grain
|
|
576
|
+
toList: (stack: ImmutableStack<a>) => List<a>
|
|
577
|
+
```
|
|
578
|
+
|
|
579
|
+
Creates a list containing the elements of a stack.
|
|
580
|
+
|
|
581
|
+
Parameters:
|
|
582
|
+
|
|
583
|
+
| param | type | description |
|
|
584
|
+
| ------- | ------------------- | -------------------- |
|
|
585
|
+
| `stack` | `ImmutableStack<a>` | The stack to convert |
|
|
586
|
+
|
|
587
|
+
Returns:
|
|
588
|
+
|
|
589
|
+
| type | description |
|
|
590
|
+
| --------- | ---------------------------------- |
|
|
591
|
+
| `List<a>` | A list containing all stack values |
|
|
592
|
+
|
|
593
|
+
Examples:
|
|
594
|
+
|
|
595
|
+
```grain
|
|
596
|
+
use Stack.{ module Immutable as Stack }
|
|
597
|
+
let stack = Stack.empty
|
|
598
|
+
let stack = Stack.push(1, stack)
|
|
599
|
+
let stack = Stack.push(2, stack)
|
|
600
|
+
assert Stack.toList(stack) == [2, 1]
|
|
601
|
+
```
|
|
602
|
+
|
|
603
|
+
#### Stack.Immutable.**fromList**
|
|
604
|
+
|
|
605
|
+
<details disabled>
|
|
606
|
+
<summary tabindex="-1">Added in <code>0.7.0</code></summary>
|
|
607
|
+
No other changes yet.
|
|
608
|
+
</details>
|
|
609
|
+
|
|
610
|
+
```grain
|
|
611
|
+
fromList: (list: List<a>) => ImmutableStack<a>
|
|
612
|
+
```
|
|
613
|
+
|
|
614
|
+
Creates a stack from a list.
|
|
615
|
+
|
|
616
|
+
Parameters:
|
|
617
|
+
|
|
618
|
+
| param | type | description |
|
|
619
|
+
| ------ | --------- | ------------------- |
|
|
620
|
+
| `list` | `List<a>` | The list to convert |
|
|
621
|
+
|
|
622
|
+
Returns:
|
|
623
|
+
|
|
624
|
+
| type | description |
|
|
625
|
+
| ------------------- | ---------------------------------- |
|
|
626
|
+
| `ImmutableStack<a>` | A stack containing all list values |
|
|
627
|
+
|
|
628
|
+
Examples:
|
|
629
|
+
|
|
630
|
+
```grain
|
|
631
|
+
use Stack.{ module Immutable as Stack }
|
|
632
|
+
let stack = Stack.fromList([2, 1])
|
|
633
|
+
assert Stack.peek(stack) == Some(2)
|
|
634
|
+
let stack = Stack.pop(stack)
|
|
635
|
+
assert Stack.peek(stack) == Some(1)
|
|
636
|
+
let stack = Stack.pop(stack)
|
|
637
|
+
assert Stack.isEmpty(stack)
|
|
638
|
+
```
|
|
639
|
+
|
|
640
|
+
#### Stack.Immutable.**toArray**
|
|
641
|
+
|
|
642
|
+
<details disabled>
|
|
643
|
+
<summary tabindex="-1">Added in <code>0.7.0</code></summary>
|
|
644
|
+
No other changes yet.
|
|
645
|
+
</details>
|
|
646
|
+
|
|
647
|
+
```grain
|
|
648
|
+
toArray: (stack: ImmutableStack<a>) => Array<a>
|
|
649
|
+
```
|
|
650
|
+
|
|
651
|
+
Creates an array containing the elements of a stack.
|
|
652
|
+
|
|
653
|
+
Parameters:
|
|
654
|
+
|
|
655
|
+
| param | type | description |
|
|
656
|
+
| ------- | ------------------- | -------------------- |
|
|
657
|
+
| `stack` | `ImmutableStack<a>` | The stack to convert |
|
|
658
|
+
|
|
659
|
+
Returns:
|
|
660
|
+
|
|
661
|
+
| type | description |
|
|
662
|
+
| ---------- | ------------------------------------ |
|
|
663
|
+
| `Array<a>` | An array containing all stack values |
|
|
664
|
+
|
|
665
|
+
Examples:
|
|
666
|
+
|
|
667
|
+
```grain
|
|
668
|
+
use Stack.{ module Immutable as Stack }
|
|
669
|
+
let stack = Stack.empty
|
|
670
|
+
let stack = Stack.push(1, stack)
|
|
671
|
+
let stack = Stack.push(2, stack)
|
|
672
|
+
assert Stack.toArray(stack) == [> 2, 1]
|
|
673
|
+
```
|
|
674
|
+
|
|
675
|
+
#### Stack.Immutable.**fromArray**
|
|
676
|
+
|
|
677
|
+
<details disabled>
|
|
678
|
+
<summary tabindex="-1">Added in <code>0.7.0</code></summary>
|
|
679
|
+
No other changes yet.
|
|
680
|
+
</details>
|
|
681
|
+
|
|
682
|
+
```grain
|
|
683
|
+
fromArray: (arr: Array<a>) => ImmutableStack<a>
|
|
684
|
+
```
|
|
685
|
+
|
|
686
|
+
Creates a stack from an array.
|
|
687
|
+
|
|
688
|
+
Parameters:
|
|
689
|
+
|
|
690
|
+
| param | type | description |
|
|
691
|
+
| ----- | ---------- | -------------------- |
|
|
692
|
+
| `arr` | `Array<a>` | The array to convert |
|
|
693
|
+
|
|
694
|
+
Returns:
|
|
695
|
+
|
|
696
|
+
| type | description |
|
|
697
|
+
| ------------------- | ----------------------------------- |
|
|
698
|
+
| `ImmutableStack<a>` | A stack containing all array values |
|
|
699
|
+
|
|
700
|
+
Examples:
|
|
701
|
+
|
|
702
|
+
```grain
|
|
703
|
+
use Stack.{ module Immutable as Stack }
|
|
704
|
+
let stack = Stack.fromArray([> 2, 1])
|
|
705
|
+
assert Stack.peek(stack) == Some(2)
|
|
706
|
+
let stack = Stack.pop(stack)
|
|
707
|
+
assert Stack.peek(stack) == Some(1)
|
|
708
|
+
let stack = Stack.pop(stack)
|
|
709
|
+
assert Stack.isEmpty(stack)
|
|
710
|
+
```
|
|
429
711
|
|