@grain/stdlib 0.4.0 → 0.4.4
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 +65 -0
- package/LICENSE +21 -0
- package/README.md +34 -0
- package/array.gr +136 -44
- package/array.md +97 -21
- package/buffer.gr +495 -424
- package/buffer.md +850 -0
- package/bytes.gr +512 -407
- package/bytes.md +621 -0
- package/char.gr +11 -3
- package/hash.gr +26 -3
- package/hash.md +44 -0
- package/list.gr +54 -0
- package/number.gr +24 -6
- package/number.md +49 -17
- package/option.gr +244 -37
- package/option.md +579 -0
- package/package.json +33 -29
- package/queue.gr +98 -29
- package/queue.md +191 -0
- package/range.md +1 -1
- package/regex.gr +3055 -0
- package/regex.md +449 -0
- package/result.gr +216 -70
- package/result.md +446 -0
- package/runtime/gc.gr +2 -2
- package/runtime/string.gr +56 -24
- package/runtime/stringUtils.gr +172 -0
- package/runtime/unsafe/conv.gr +43 -0
- package/set.gr +172 -5
- package/set.md +502 -0
- package/stack.md +143 -0
- package/string.gr +444 -230
- package/string.md +815 -0
- package/sys/file.gr +3 -2
- package/sys/file.md +2 -2
package/set.md
ADDED
|
@@ -0,0 +1,502 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Set
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
A Set is an unordered collection of unique values. Operations on a Set mutate the internal state, so it never needs to be re-assigned.
|
|
6
|
+
|
|
7
|
+
<details disabled>
|
|
8
|
+
<summary tabindex="-1">Added in <code>0.3.0</code></summary>
|
|
9
|
+
No other changes yet.
|
|
10
|
+
</details>
|
|
11
|
+
|
|
12
|
+
```grain
|
|
13
|
+
import Set from "set"
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
### Set.**Bucket**
|
|
17
|
+
|
|
18
|
+
```grain
|
|
19
|
+
record Bucket<t> {
|
|
20
|
+
key: t,
|
|
21
|
+
next: Option<Bucket<t>>,
|
|
22
|
+
}
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
### Set.**Set**
|
|
26
|
+
|
|
27
|
+
```grain
|
|
28
|
+
record Set<k> {
|
|
29
|
+
size: Number,
|
|
30
|
+
buckets: Array<Option<Bucket<k>>>,
|
|
31
|
+
}
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### Set.**makeSized**
|
|
35
|
+
|
|
36
|
+
<details disabled>
|
|
37
|
+
<summary tabindex="-1">Added in <code>0.3.0</code></summary>
|
|
38
|
+
No other changes yet.
|
|
39
|
+
</details>
|
|
40
|
+
|
|
41
|
+
```grain
|
|
42
|
+
makeSized : Number -> Set<a>
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Creates a new empty set with an initial storage of the given length. As values are added or removed, the length may grow or shrink. Generally, you won't need to care about the length of your set and can use `Set.make()` instead.
|
|
46
|
+
|
|
47
|
+
Parameters:
|
|
48
|
+
|
|
49
|
+
|param|type|description|
|
|
50
|
+
|-----|----|-----------|
|
|
51
|
+
|`storageLength`|`Number`|The initial storage length of the set|
|
|
52
|
+
|
|
53
|
+
Returns:
|
|
54
|
+
|
|
55
|
+
|type|description|
|
|
56
|
+
|----|-----------|
|
|
57
|
+
|`Set<a>`|An empty set with the given initial storage length|
|
|
58
|
+
|
|
59
|
+
### Set.**make**
|
|
60
|
+
|
|
61
|
+
<details disabled>
|
|
62
|
+
<summary tabindex="-1">Added in <code>0.3.0</code></summary>
|
|
63
|
+
No other changes yet.
|
|
64
|
+
</details>
|
|
65
|
+
|
|
66
|
+
```grain
|
|
67
|
+
make : () -> Set<a>
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
Creates a new, empty set.
|
|
71
|
+
|
|
72
|
+
Returns:
|
|
73
|
+
|
|
74
|
+
|type|description|
|
|
75
|
+
|----|-----------|
|
|
76
|
+
|`Set<a>`|An empty set|
|
|
77
|
+
|
|
78
|
+
### Set.**add**
|
|
79
|
+
|
|
80
|
+
<details disabled>
|
|
81
|
+
<summary tabindex="-1">Added in <code>0.3.0</code></summary>
|
|
82
|
+
No other changes yet.
|
|
83
|
+
</details>
|
|
84
|
+
|
|
85
|
+
```grain
|
|
86
|
+
add : (a, Set<a>) -> Void
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
Adds a new value to the set. If the value already exists, nothing happens.
|
|
90
|
+
|
|
91
|
+
Parameters:
|
|
92
|
+
|
|
93
|
+
|param|type|description|
|
|
94
|
+
|-----|----|-----------|
|
|
95
|
+
|`key`|`a`|The value to add|
|
|
96
|
+
|`set`|`Set<a>`|The set to update|
|
|
97
|
+
|
|
98
|
+
### Set.**contains**
|
|
99
|
+
|
|
100
|
+
<details disabled>
|
|
101
|
+
<summary tabindex="-1">Added in <code>0.3.0</code></summary>
|
|
102
|
+
No other changes yet.
|
|
103
|
+
</details>
|
|
104
|
+
|
|
105
|
+
```grain
|
|
106
|
+
contains : (a, Set<a>) -> Bool
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
Determines if the set contains the given value.
|
|
110
|
+
|
|
111
|
+
Parameters:
|
|
112
|
+
|
|
113
|
+
|param|type|description|
|
|
114
|
+
|-----|----|-----------|
|
|
115
|
+
|`key`|`a`|The value to search for|
|
|
116
|
+
|`set`|`Set<a>`|The set to search|
|
|
117
|
+
|
|
118
|
+
Returns:
|
|
119
|
+
|
|
120
|
+
|type|description|
|
|
121
|
+
|----|-----------|
|
|
122
|
+
|`Bool`|`true` if the set contains the given value or `false` otherwise|
|
|
123
|
+
|
|
124
|
+
### Set.**remove**
|
|
125
|
+
|
|
126
|
+
<details disabled>
|
|
127
|
+
<summary tabindex="-1">Added in <code>0.3.0</code></summary>
|
|
128
|
+
No other changes yet.
|
|
129
|
+
</details>
|
|
130
|
+
|
|
131
|
+
```grain
|
|
132
|
+
remove : (a, Set<a>) -> Void
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
Removes the given value from the set. If the value doesn't exist, nothing happens.
|
|
136
|
+
|
|
137
|
+
Parameters:
|
|
138
|
+
|
|
139
|
+
|param|type|description|
|
|
140
|
+
|-----|----|-----------|
|
|
141
|
+
|`key`|`a`|The value to remove|
|
|
142
|
+
|`set`|`Set<a>`|The set to update|
|
|
143
|
+
|
|
144
|
+
### Set.**size**
|
|
145
|
+
|
|
146
|
+
<details disabled>
|
|
147
|
+
<summary tabindex="-1">Added in <code>0.3.0</code></summary>
|
|
148
|
+
No other changes yet.
|
|
149
|
+
</details>
|
|
150
|
+
|
|
151
|
+
```grain
|
|
152
|
+
size : Set<a> -> Number
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
Returns the number of values within the set.
|
|
156
|
+
|
|
157
|
+
Parameters:
|
|
158
|
+
|
|
159
|
+
|param|type|description|
|
|
160
|
+
|-----|----|-----------|
|
|
161
|
+
|`set`|`Set<a>`|The set to inspect|
|
|
162
|
+
|
|
163
|
+
Returns:
|
|
164
|
+
|
|
165
|
+
|type|description|
|
|
166
|
+
|----|-----------|
|
|
167
|
+
|`Number`|The number of elements in the set|
|
|
168
|
+
|
|
169
|
+
### Set.**isEmpty**
|
|
170
|
+
|
|
171
|
+
<details disabled>
|
|
172
|
+
<summary tabindex="-1">Added in <code>0.3.0</code></summary>
|
|
173
|
+
No other changes yet.
|
|
174
|
+
</details>
|
|
175
|
+
|
|
176
|
+
```grain
|
|
177
|
+
isEmpty : Set<a> -> Bool
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
Determines if the set contains no elements.
|
|
181
|
+
|
|
182
|
+
Parameters:
|
|
183
|
+
|
|
184
|
+
|param|type|description|
|
|
185
|
+
|-----|----|-----------|
|
|
186
|
+
|`set`|`Set<a>`|The set to inspect|
|
|
187
|
+
|
|
188
|
+
Returns:
|
|
189
|
+
|
|
190
|
+
|type|description|
|
|
191
|
+
|----|-----------|
|
|
192
|
+
|`Bool`|`true` if the given set is empty or `false` otherwise|
|
|
193
|
+
|
|
194
|
+
### Set.**clear**
|
|
195
|
+
|
|
196
|
+
<details disabled>
|
|
197
|
+
<summary tabindex="-1">Added in <code>0.3.0</code></summary>
|
|
198
|
+
No other changes yet.
|
|
199
|
+
</details>
|
|
200
|
+
|
|
201
|
+
```grain
|
|
202
|
+
clear : Set<a> -> Void
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
Resets the set by removing all values.
|
|
206
|
+
|
|
207
|
+
Parameters:
|
|
208
|
+
|
|
209
|
+
|param|type|description|
|
|
210
|
+
|-----|----|-----------|
|
|
211
|
+
|`set`|`Set<a>`|The set to reset|
|
|
212
|
+
|
|
213
|
+
### Set.**forEach**
|
|
214
|
+
|
|
215
|
+
<details disabled>
|
|
216
|
+
<summary tabindex="-1">Added in <code>0.3.0</code></summary>
|
|
217
|
+
No other changes yet.
|
|
218
|
+
</details>
|
|
219
|
+
|
|
220
|
+
```grain
|
|
221
|
+
forEach : ((a -> b), Set<a>) -> Void
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
Iterates the set, calling an iterator function on each element.
|
|
225
|
+
|
|
226
|
+
Parameters:
|
|
227
|
+
|
|
228
|
+
|param|type|description|
|
|
229
|
+
|-----|----|-----------|
|
|
230
|
+
|`fn`|`a -> b`|The iterator function to call with each element|
|
|
231
|
+
|`set`|`Set<a>`|The set to iterate|
|
|
232
|
+
|
|
233
|
+
### Set.**reduce**
|
|
234
|
+
|
|
235
|
+
<details disabled>
|
|
236
|
+
<summary tabindex="-1">Added in <code>0.3.0</code></summary>
|
|
237
|
+
No other changes yet.
|
|
238
|
+
</details>
|
|
239
|
+
|
|
240
|
+
```grain
|
|
241
|
+
reduce : (((a, b) -> a), a, Set<b>) -> a
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
Combines all elements of a set using a reducer function.
|
|
245
|
+
|
|
246
|
+
Parameters:
|
|
247
|
+
|
|
248
|
+
|param|type|description|
|
|
249
|
+
|-----|----|-----------|
|
|
250
|
+
|`fn`|`(a, b) -> a`|The reducer function to call on each element, where the value returned will be the next accumulator value|
|
|
251
|
+
|`init`|`a`|The initial value to use for the accumulator on the first iteration|
|
|
252
|
+
|`set`|`Set<b>`|The set to iterate|
|
|
253
|
+
|
|
254
|
+
Returns:
|
|
255
|
+
|
|
256
|
+
|type|description|
|
|
257
|
+
|----|-----------|
|
|
258
|
+
|`a`|The final accumulator returned from `fn`|
|
|
259
|
+
|
|
260
|
+
### Set.**filter**
|
|
261
|
+
|
|
262
|
+
<details disabled>
|
|
263
|
+
<summary tabindex="-1">Added in <code>0.3.0</code></summary>
|
|
264
|
+
No other changes yet.
|
|
265
|
+
</details>
|
|
266
|
+
|
|
267
|
+
```grain
|
|
268
|
+
filter : ((a -> Bool), Set<a>) -> Void
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
Removes elements from a set where a predicate function returns `false`.
|
|
272
|
+
|
|
273
|
+
Parameters:
|
|
274
|
+
|
|
275
|
+
|param|type|description|
|
|
276
|
+
|-----|----|-----------|
|
|
277
|
+
|`fn`|`a -> Bool`|The predicate function to indicate which elements to remove from the set, where returning `false` indicates the value should be removed|
|
|
278
|
+
|`set`|`Set<a>`|The set to iterate|
|
|
279
|
+
|
|
280
|
+
### Set.**reject**
|
|
281
|
+
|
|
282
|
+
<details disabled>
|
|
283
|
+
<summary tabindex="-1">Added in <code>0.3.0</code></summary>
|
|
284
|
+
No other changes yet.
|
|
285
|
+
</details>
|
|
286
|
+
|
|
287
|
+
```grain
|
|
288
|
+
reject : ((a -> Bool), Set<a>) -> Void
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
Removes elements from a set where a predicate function returns `true`.
|
|
292
|
+
|
|
293
|
+
Parameters:
|
|
294
|
+
|
|
295
|
+
|param|type|description|
|
|
296
|
+
|-----|----|-----------|
|
|
297
|
+
|`fn`|`a -> Bool`|The predicate function to indicate which elements to remove from the set, where returning `true` indicates the value should be removed|
|
|
298
|
+
|`set`|`Set<a>`|The set to iterate|
|
|
299
|
+
|
|
300
|
+
### Set.**toList**
|
|
301
|
+
|
|
302
|
+
<details disabled>
|
|
303
|
+
<summary tabindex="-1">Added in <code>0.3.0</code></summary>
|
|
304
|
+
No other changes yet.
|
|
305
|
+
</details>
|
|
306
|
+
|
|
307
|
+
```grain
|
|
308
|
+
toList : Set<a> -> List<a>
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
Converts a set into a list of its elements.
|
|
312
|
+
|
|
313
|
+
Parameters:
|
|
314
|
+
|
|
315
|
+
|param|type|description|
|
|
316
|
+
|-----|----|-----------|
|
|
317
|
+
|`set`|`Set<a>`|The set to convert|
|
|
318
|
+
|
|
319
|
+
Returns:
|
|
320
|
+
|
|
321
|
+
|type|description|
|
|
322
|
+
|----|-----------|
|
|
323
|
+
|`List<a>`|A list containing all set values|
|
|
324
|
+
|
|
325
|
+
### Set.**fromList**
|
|
326
|
+
|
|
327
|
+
<details disabled>
|
|
328
|
+
<summary tabindex="-1">Added in <code>0.3.0</code></summary>
|
|
329
|
+
No other changes yet.
|
|
330
|
+
</details>
|
|
331
|
+
|
|
332
|
+
```grain
|
|
333
|
+
fromList : List<a> -> Set<a>
|
|
334
|
+
```
|
|
335
|
+
|
|
336
|
+
Creates a set from a list.
|
|
337
|
+
|
|
338
|
+
Parameters:
|
|
339
|
+
|
|
340
|
+
|param|type|description|
|
|
341
|
+
|-----|----|-----------|
|
|
342
|
+
|`list`|`List<a>`|The list to convert|
|
|
343
|
+
|
|
344
|
+
Returns:
|
|
345
|
+
|
|
346
|
+
|type|description|
|
|
347
|
+
|----|-----------|
|
|
348
|
+
|`Set<a>`|A set containing all list values|
|
|
349
|
+
|
|
350
|
+
### Set.**toArray**
|
|
351
|
+
|
|
352
|
+
<details disabled>
|
|
353
|
+
<summary tabindex="-1">Added in <code>0.3.0</code></summary>
|
|
354
|
+
No other changes yet.
|
|
355
|
+
</details>
|
|
356
|
+
|
|
357
|
+
```grain
|
|
358
|
+
toArray : Set<a> -> Array<a>
|
|
359
|
+
```
|
|
360
|
+
|
|
361
|
+
Converts a set into an array of its elements.
|
|
362
|
+
|
|
363
|
+
Parameters:
|
|
364
|
+
|
|
365
|
+
|param|type|description|
|
|
366
|
+
|-----|----|-----------|
|
|
367
|
+
|`set`|`Set<a>`|The set to convert|
|
|
368
|
+
|
|
369
|
+
Returns:
|
|
370
|
+
|
|
371
|
+
|type|description|
|
|
372
|
+
|----|-----------|
|
|
373
|
+
|`Array<a>`|An array containing all set values|
|
|
374
|
+
|
|
375
|
+
### Set.**fromArray**
|
|
376
|
+
|
|
377
|
+
<details disabled>
|
|
378
|
+
<summary tabindex="-1">Added in <code>0.3.0</code></summary>
|
|
379
|
+
No other changes yet.
|
|
380
|
+
</details>
|
|
381
|
+
|
|
382
|
+
```grain
|
|
383
|
+
fromArray : Array<a> -> Set<a>
|
|
384
|
+
```
|
|
385
|
+
|
|
386
|
+
Creates a set from an array.
|
|
387
|
+
|
|
388
|
+
Parameters:
|
|
389
|
+
|
|
390
|
+
|param|type|description|
|
|
391
|
+
|-----|----|-----------|
|
|
392
|
+
|`array`|`Array<a>`|The array to convert|
|
|
393
|
+
|
|
394
|
+
Returns:
|
|
395
|
+
|
|
396
|
+
|type|description|
|
|
397
|
+
|----|-----------|
|
|
398
|
+
|`Set<a>`|A set containing all array values|
|
|
399
|
+
|
|
400
|
+
### Set.**union**
|
|
401
|
+
|
|
402
|
+
<details disabled>
|
|
403
|
+
<summary tabindex="-1">Added in <code>0.3.0</code></summary>
|
|
404
|
+
No other changes yet.
|
|
405
|
+
</details>
|
|
406
|
+
|
|
407
|
+
```grain
|
|
408
|
+
union : (Set<a>, Set<a>) -> Set<a>
|
|
409
|
+
```
|
|
410
|
+
|
|
411
|
+
Combines two sets into a single set containing all elements from both sets.
|
|
412
|
+
|
|
413
|
+
Parameters:
|
|
414
|
+
|
|
415
|
+
|param|type|description|
|
|
416
|
+
|-----|----|-----------|
|
|
417
|
+
|`set1`|`Set<a>`|The first set to combine|
|
|
418
|
+
|`set2`|`Set<a>`|The second set to combine|
|
|
419
|
+
|
|
420
|
+
Returns:
|
|
421
|
+
|
|
422
|
+
|type|description|
|
|
423
|
+
|----|-----------|
|
|
424
|
+
|`Set<a>`|A set containing all elements of both sets|
|
|
425
|
+
|
|
426
|
+
### Set.**diff**
|
|
427
|
+
|
|
428
|
+
<details disabled>
|
|
429
|
+
<summary tabindex="-1">Added in <code>0.3.0</code></summary>
|
|
430
|
+
No other changes yet.
|
|
431
|
+
</details>
|
|
432
|
+
|
|
433
|
+
```grain
|
|
434
|
+
diff : (Set<a>, Set<a>) -> Set<a>
|
|
435
|
+
```
|
|
436
|
+
|
|
437
|
+
Combines two sets into a single set containing only the elements not shared between both sets.
|
|
438
|
+
|
|
439
|
+
Parameters:
|
|
440
|
+
|
|
441
|
+
|param|type|description|
|
|
442
|
+
|-----|----|-----------|
|
|
443
|
+
|`set1`|`Set<a>`|The first set to combine|
|
|
444
|
+
|`set2`|`Set<a>`|The second set to combine|
|
|
445
|
+
|
|
446
|
+
Returns:
|
|
447
|
+
|
|
448
|
+
|type|description|
|
|
449
|
+
|----|-----------|
|
|
450
|
+
|`Set<a>`|A set containing only unshared elements from both sets|
|
|
451
|
+
|
|
452
|
+
### Set.**intersect**
|
|
453
|
+
|
|
454
|
+
<details disabled>
|
|
455
|
+
<summary tabindex="-1">Added in <code>0.3.0</code></summary>
|
|
456
|
+
No other changes yet.
|
|
457
|
+
</details>
|
|
458
|
+
|
|
459
|
+
```grain
|
|
460
|
+
intersect : (Set<a>, Set<a>) -> Set<a>
|
|
461
|
+
```
|
|
462
|
+
|
|
463
|
+
Combines two sets into a single set containing only the elements shared between both sets.
|
|
464
|
+
|
|
465
|
+
Parameters:
|
|
466
|
+
|
|
467
|
+
|param|type|description|
|
|
468
|
+
|-----|----|-----------|
|
|
469
|
+
|`set1`|`Set<a>`|The first set to combine|
|
|
470
|
+
|`set2`|`Set<a>`|The second set to combine|
|
|
471
|
+
|
|
472
|
+
Returns:
|
|
473
|
+
|
|
474
|
+
|type|description|
|
|
475
|
+
|----|-----------|
|
|
476
|
+
|`Set<a>`|A set containing only shared elements from both sets|
|
|
477
|
+
|
|
478
|
+
### Set.**getInternalStats**
|
|
479
|
+
|
|
480
|
+
<details disabled>
|
|
481
|
+
<summary tabindex="-1">Added in <code>0.3.0</code></summary>
|
|
482
|
+
No other changes yet.
|
|
483
|
+
</details>
|
|
484
|
+
|
|
485
|
+
```grain
|
|
486
|
+
getInternalStats : Set<a> -> (Number, Number)
|
|
487
|
+
```
|
|
488
|
+
|
|
489
|
+
Provides data representing the internal state state of the set.
|
|
490
|
+
|
|
491
|
+
Parameters:
|
|
492
|
+
|
|
493
|
+
|param|type|description|
|
|
494
|
+
|-----|----|-----------|
|
|
495
|
+
|`set`|`Set<a>`|The set to inspect|
|
|
496
|
+
|
|
497
|
+
Returns:
|
|
498
|
+
|
|
499
|
+
|type|description|
|
|
500
|
+
|----|-----------|
|
|
501
|
+
|`(Number, Number)`|The internal state of the set|
|
|
502
|
+
|
package/stack.md
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Stack
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
An immutable stack implementation. A stack is a LIFO (last-in-first-out) data structure where new values are added, retrieved, and removed from the end.
|
|
6
|
+
|
|
7
|
+
```grain
|
|
8
|
+
import Stack from "stack"
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Types
|
|
12
|
+
|
|
13
|
+
Type declarations included in the Stack module.
|
|
14
|
+
|
|
15
|
+
### Stack.**Stack**
|
|
16
|
+
|
|
17
|
+
```grain
|
|
18
|
+
record Stack<a> {
|
|
19
|
+
data: List<a>,
|
|
20
|
+
}
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Stacks are immutable data structures that store their data in a List.
|
|
24
|
+
|
|
25
|
+
## Values
|
|
26
|
+
|
|
27
|
+
Functions and constants included in the Stack module.
|
|
28
|
+
|
|
29
|
+
### Stack.**make**
|
|
30
|
+
|
|
31
|
+
```grain
|
|
32
|
+
make : () -> Stack<a>
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Creates a new stack.
|
|
36
|
+
|
|
37
|
+
Returns:
|
|
38
|
+
|
|
39
|
+
|type|description|
|
|
40
|
+
|----|-----------|
|
|
41
|
+
|`Stack<a>`|An empty stack|
|
|
42
|
+
|
|
43
|
+
### Stack.**isEmpty**
|
|
44
|
+
|
|
45
|
+
```grain
|
|
46
|
+
isEmpty : Stack<a> -> Bool
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Checks if the given stack contains no items.
|
|
50
|
+
|
|
51
|
+
Parameters:
|
|
52
|
+
|
|
53
|
+
|param|type|description|
|
|
54
|
+
|-----|----|-----------|
|
|
55
|
+
|`stack`|`Stack<a>`|The stack to check|
|
|
56
|
+
|
|
57
|
+
Returns:
|
|
58
|
+
|
|
59
|
+
|type|description|
|
|
60
|
+
|----|-----------|
|
|
61
|
+
|`Bool`|`true` if the stack has no items, and `false` otherwise|
|
|
62
|
+
|
|
63
|
+
### Stack.**peek**
|
|
64
|
+
|
|
65
|
+
```grain
|
|
66
|
+
peek : Stack<a> -> Option<a>
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
Returns `Some(item)` where `item` is the value at the top of the stack, and `None` otherwise.
|
|
70
|
+
|
|
71
|
+
Parameters:
|
|
72
|
+
|
|
73
|
+
|param|type|description|
|
|
74
|
+
|-----|----|-----------|
|
|
75
|
+
|`stack`|`Stack<a>`|The stack to inspect|
|
|
76
|
+
|
|
77
|
+
Returns:
|
|
78
|
+
|
|
79
|
+
|type|description|
|
|
80
|
+
|----|-----------|
|
|
81
|
+
|`Option<a>`|The value at the top of the stack, if it exists|
|
|
82
|
+
|
|
83
|
+
### Stack.**push**
|
|
84
|
+
|
|
85
|
+
```grain
|
|
86
|
+
push : (a, Stack<a>) -> Stack<a>
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
Adds a new item to the top of the stack.
|
|
90
|
+
|
|
91
|
+
Parameters:
|
|
92
|
+
|
|
93
|
+
|param|type|description|
|
|
94
|
+
|-----|----|-----------|
|
|
95
|
+
|`value`|`a`|The item to be added|
|
|
96
|
+
|`stack`|`Stack<a>`|The stack being updated|
|
|
97
|
+
|
|
98
|
+
Returns:
|
|
99
|
+
|
|
100
|
+
|type|description|
|
|
101
|
+
|----|-----------|
|
|
102
|
+
|`Stack<a>`|A new stack with the item added to the end|
|
|
103
|
+
|
|
104
|
+
### Stack.**pop**
|
|
105
|
+
|
|
106
|
+
```grain
|
|
107
|
+
pop : Stack<a> -> Stack<a>
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
Removes the item at the top of the stack.
|
|
111
|
+
|
|
112
|
+
Parameters:
|
|
113
|
+
|
|
114
|
+
|param|type|description|
|
|
115
|
+
|-----|----|-----------|
|
|
116
|
+
|`stack`|`Stack<a>`|The stack being updated|
|
|
117
|
+
|
|
118
|
+
Returns:
|
|
119
|
+
|
|
120
|
+
|type|description|
|
|
121
|
+
|----|-----------|
|
|
122
|
+
|`Stack<a>`|A new stack with the last item removed|
|
|
123
|
+
|
|
124
|
+
### Stack.**size**
|
|
125
|
+
|
|
126
|
+
```grain
|
|
127
|
+
size : Stack<a> -> Number
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
Computes the size of the input stack.
|
|
131
|
+
|
|
132
|
+
Parameters:
|
|
133
|
+
|
|
134
|
+
|param|type|description|
|
|
135
|
+
|-----|----|-----------|
|
|
136
|
+
|`stack`|`Stack<a>`|The stack to inspect|
|
|
137
|
+
|
|
138
|
+
Returns:
|
|
139
|
+
|
|
140
|
+
|type|description|
|
|
141
|
+
|----|-----------|
|
|
142
|
+
|`Number`|The count of the items in the stack|
|
|
143
|
+
|