@grain/stdlib 0.4.1 → 0.4.5
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 +63 -0
- package/LICENSE +21 -0
- package/README.md +34 -0
- package/array.gr +200 -89
- package/array.md +81 -5
- package/buffer.gr +93 -36
- package/bytes.gr +512 -407
- package/bytes.md +621 -0
- package/char.gr +119 -55
- package/char.md +200 -0
- package/hash.gr +42 -15
- package/hash.md +44 -0
- package/list.gr +121 -50
- package/map.gr +106 -110
- package/number.gr +37 -1
- package/number.md +66 -0
- package/option.gr +260 -53
- package/option.md +579 -0
- package/package.json +33 -29
- package/pervasives.gr +32 -20
- package/queue.gr +102 -30
- package/queue.md +191 -0
- package/range.gr +26 -26
- 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/dataStructures.gr +28 -29
- package/runtime/debug.gr +0 -1
- package/runtime/equal.gr +37 -16
- package/runtime/exception.gr +28 -15
- package/runtime/gc.gr +33 -20
- package/runtime/malloc.gr +19 -11
- package/runtime/numberUtils.gr +208 -105
- package/runtime/numbers.gr +217 -118
- package/runtime/string.gr +150 -59
- package/runtime/stringUtils.gr +176 -0
- package/runtime/unsafe/conv.gr +51 -8
- package/runtime/unsafe/memory.gr +14 -3
- package/runtime/unsafe/printWasm.gr +4 -4
- package/runtime/unsafe/tags.gr +2 -2
- package/runtime/unsafe/wasmf32.gr +9 -2
- package/runtime/unsafe/wasmf64.gr +9 -2
- package/runtime/unsafe/wasmi32.gr +65 -47
- package/runtime/unsafe/wasmi64.gr +78 -50
- package/runtime/wasi.gr +199 -45
- package/set.gr +281 -119
- package/set.md +502 -0
- package/stack.gr +26 -26
- package/stack.md +143 -0
- package/string.gr +697 -329
- package/string.md +815 -0
- package/sys/file.gr +356 -177
- package/sys/process.gr +10 -6
- package/sys/random.gr +3 -6
- package/sys/time.gr +3 -3
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
|
+
|