@shd101wyy/yo 0.1.25 → 0.1.27

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.
Files changed (194) hide show
  1. package/.github/skills/yo-async-effects/SKILL.md +4 -4
  2. package/.github/skills/yo-async-effects/async-effects-recipes.md +40 -40
  3. package/.github/skills/yo-core-patterns/SKILL.md +1 -1
  4. package/.github/skills/yo-core-patterns/core-patterns-cheatsheet.md +30 -26
  5. package/.github/skills/yo-project-workflow/SKILL.md +6 -3
  6. package/.github/skills/yo-project-workflow/workflow-cheatsheet.md +34 -11
  7. package/.github/skills/yo-syntax/SKILL.md +7 -6
  8. package/.github/skills/yo-syntax/syntax-cheatsheet.md +78 -60
  9. package/.github/skills/yo-wasm-integration/wasm-integration-cheatsheet.md +3 -3
  10. package/README.md +10 -8
  11. package/out/cjs/index.cjs +583 -567
  12. package/out/cjs/yo-cli.cjs +664 -632
  13. package/out/cjs/yo-lsp.cjs +510 -485
  14. package/out/esm/index.mjs +538 -522
  15. package/out/types/src/codegen/codegen-c.d.ts +2 -2
  16. package/out/types/src/codegen/functions/collection.d.ts +2 -2
  17. package/out/types/src/codegen/functions/context.d.ts +3 -2
  18. package/out/types/src/codegen/types/collection.d.ts +2 -2
  19. package/out/types/src/codegen/utils/index.d.ts +3 -1
  20. package/out/types/src/doc/builder.d.ts +2 -2
  21. package/out/types/src/evaluator/calls/closure-type.d.ts +2 -2
  22. package/out/types/src/evaluator/calls/record-type.d.ts +11 -0
  23. package/out/types/src/evaluator/context.d.ts +8 -9
  24. package/out/types/src/evaluator/index.d.ts +3 -3
  25. package/out/types/src/evaluator/types/record.d.ts +14 -0
  26. package/out/types/src/evaluator/types/validation.d.ts +2 -2
  27. package/out/types/src/evaluator/values/anonymous-module.d.ts +5 -5
  28. package/out/types/src/evaluator/values/impl.d.ts +1 -1
  29. package/out/types/src/expr.d.ts +1 -4
  30. package/out/types/src/formatter.d.ts +11 -0
  31. package/out/types/src/function-value.d.ts +1 -1
  32. package/out/types/src/lsp/document-manager.d.ts +1 -1
  33. package/out/types/src/lsp/formatting.d.ts +2 -0
  34. package/out/types/src/module-manager.d.ts +3 -3
  35. package/out/types/src/tests/formatter.test.d.ts +1 -0
  36. package/out/types/src/types/creators.d.ts +3 -4
  37. package/out/types/src/types/definitions.d.ts +8 -19
  38. package/out/types/src/types/guards.d.ts +3 -3
  39. package/out/types/src/types/tags.d.ts +0 -1
  40. package/out/types/src/types/utils.d.ts +1 -1
  41. package/out/types/src/value-tag.d.ts +0 -1
  42. package/out/types/src/value.d.ts +6 -13
  43. package/out/types/tsconfig.tsbuildinfo +1 -1
  44. package/package.json +1 -1
  45. package/std/alg/hash.yo +13 -21
  46. package/std/allocator.yo +25 -40
  47. package/std/async.yo +3 -7
  48. package/std/build.yo +105 -151
  49. package/std/cli/arg_parser.yo +184 -169
  50. package/std/collections/array_list.yo +350 -314
  51. package/std/collections/btree_map.yo +142 -131
  52. package/std/collections/deque.yo +132 -128
  53. package/std/collections/hash_map.yo +542 -566
  54. package/std/collections/hash_set.yo +623 -687
  55. package/std/collections/linked_list.yo +275 -293
  56. package/std/collections/ordered_map.yo +113 -85
  57. package/std/collections/priority_queue.yo +73 -73
  58. package/std/crypto/md5.yo +191 -95
  59. package/std/crypto/random.yo +56 -64
  60. package/std/crypto/sha256.yo +151 -107
  61. package/std/encoding/base64.yo +87 -81
  62. package/std/encoding/hex.yo +43 -50
  63. package/std/encoding/html.yo +56 -81
  64. package/std/encoding/html_char_utils.yo +7 -13
  65. package/std/encoding/html_entities.yo +2248 -2253
  66. package/std/encoding/json.yo +316 -224
  67. package/std/encoding/punycode.yo +86 -116
  68. package/std/encoding/toml.yo +67 -66
  69. package/std/encoding/utf16.yo +37 -44
  70. package/std/env.yo +62 -91
  71. package/std/error.yo +12 -20
  72. package/std/fmt/display.yo +5 -9
  73. package/std/fmt/index.yo +8 -14
  74. package/std/fmt/to_string.yo +330 -315
  75. package/std/fmt/writer.yo +58 -87
  76. package/std/fs/dir.yo +83 -102
  77. package/std/fs/file.yo +147 -180
  78. package/std/fs/metadata.yo +45 -78
  79. package/std/fs/temp.yo +55 -65
  80. package/std/fs/types.yo +27 -40
  81. package/std/fs/walker.yo +53 -68
  82. package/std/gc.yo +5 -8
  83. package/std/glob.yo +30 -43
  84. package/std/http/client.yo +107 -120
  85. package/std/http/http.yo +106 -96
  86. package/std/http/index.yo +4 -6
  87. package/std/imm/list.yo +88 -93
  88. package/std/imm/map.yo +528 -464
  89. package/std/imm/set.yo +52 -57
  90. package/std/imm/sorted_map.yo +340 -286
  91. package/std/imm/sorted_set.yo +57 -63
  92. package/std/imm/string.yo +404 -345
  93. package/std/imm/vec.yo +173 -181
  94. package/std/io/reader.yo +3 -6
  95. package/std/io/writer.yo +4 -8
  96. package/std/libc/assert.yo +5 -9
  97. package/std/libc/ctype.yo +32 -22
  98. package/std/libc/dirent.yo +26 -25
  99. package/std/libc/errno.yo +164 -90
  100. package/std/libc/fcntl.yo +52 -45
  101. package/std/libc/float.yo +66 -44
  102. package/std/libc/limits.yo +42 -33
  103. package/std/libc/math.yo +53 -82
  104. package/std/libc/signal.yo +72 -47
  105. package/std/libc/stdatomic.yo +217 -188
  106. package/std/libc/stdint.yo +5 -29
  107. package/std/libc/stdio.yo +5 -29
  108. package/std/libc/stdlib.yo +32 -39
  109. package/std/libc/string.yo +5 -23
  110. package/std/libc/sys/stat.yo +58 -56
  111. package/std/libc/time.yo +5 -19
  112. package/std/libc/unistd.yo +5 -20
  113. package/std/libc/wctype.yo +6 -9
  114. package/std/libc/windows.yo +26 -30
  115. package/std/log.yo +41 -55
  116. package/std/net/addr.yo +102 -97
  117. package/std/net/dns.yo +27 -28
  118. package/std/net/errors.yo +50 -49
  119. package/std/net/tcp.yo +113 -124
  120. package/std/net/udp.yo +55 -66
  121. package/std/os/env.yo +35 -33
  122. package/std/os/signal.yo +15 -25
  123. package/std/path.yo +276 -311
  124. package/std/prelude.yo +6316 -4333
  125. package/std/process/command.yo +87 -103
  126. package/std/process/index.yo +12 -31
  127. package/std/regex/compiler.yo +196 -95
  128. package/std/regex/flags.yo +58 -39
  129. package/std/regex/index.yo +157 -173
  130. package/std/regex/match.yo +20 -31
  131. package/std/regex/node.yo +134 -152
  132. package/std/regex/parser.yo +283 -259
  133. package/std/regex/unicode.yo +172 -202
  134. package/std/regex/vm.yo +155 -171
  135. package/std/string/index.yo +5 -7
  136. package/std/string/rune.yo +45 -55
  137. package/std/string/string.yo +937 -964
  138. package/std/string/string_builder.yo +94 -104
  139. package/std/string/unicode.yo +46 -64
  140. package/std/sync/channel.yo +72 -73
  141. package/std/sync/cond.yo +31 -36
  142. package/std/sync/mutex.yo +30 -32
  143. package/std/sync/once.yo +13 -16
  144. package/std/sync/rwlock.yo +26 -31
  145. package/std/sync/waitgroup.yo +20 -25
  146. package/std/sys/advise.yo +16 -24
  147. package/std/sys/bufio/buf_reader.yo +77 -93
  148. package/std/sys/bufio/buf_writer.yo +52 -65
  149. package/std/sys/clock.yo +4 -9
  150. package/std/sys/constants.yo +77 -61
  151. package/std/sys/copy.yo +4 -10
  152. package/std/sys/dir.yo +26 -43
  153. package/std/sys/dns.yo +41 -61
  154. package/std/sys/errors.yo +95 -103
  155. package/std/sys/events.yo +45 -57
  156. package/std/sys/externs.yo +319 -267
  157. package/std/sys/fallocate.yo +7 -11
  158. package/std/sys/fcntl.yo +14 -22
  159. package/std/sys/file.yo +26 -40
  160. package/std/sys/future.yo +5 -8
  161. package/std/sys/iov.yo +12 -25
  162. package/std/sys/lock.yo +12 -13
  163. package/std/sys/mmap.yo +38 -43
  164. package/std/sys/path.yo +3 -8
  165. package/std/sys/perm.yo +7 -21
  166. package/std/sys/pipe.yo +5 -12
  167. package/std/sys/process.yo +23 -29
  168. package/std/sys/seek.yo +10 -12
  169. package/std/sys/signal.yo +7 -13
  170. package/std/sys/signals.yo +52 -35
  171. package/std/sys/socket.yo +63 -58
  172. package/std/sys/socketpair.yo +3 -6
  173. package/std/sys/sockinfo.yo +11 -20
  174. package/std/sys/statfs.yo +11 -34
  175. package/std/sys/statx.yo +25 -52
  176. package/std/sys/sysinfo.yo +15 -20
  177. package/std/sys/tcp.yo +62 -92
  178. package/std/sys/temp.yo +5 -9
  179. package/std/sys/time.yo +5 -15
  180. package/std/sys/timer.yo +6 -11
  181. package/std/sys/tty.yo +10 -18
  182. package/std/sys/udp.yo +22 -39
  183. package/std/sys/umask.yo +3 -6
  184. package/std/sys/unix.yo +33 -52
  185. package/std/testing/bench.yo +49 -52
  186. package/std/thread.yo +10 -15
  187. package/std/time/datetime.yo +105 -89
  188. package/std/time/duration.yo +43 -56
  189. package/std/time/instant.yo +13 -18
  190. package/std/time/sleep.yo +5 -9
  191. package/std/url/index.yo +184 -209
  192. package/std/worker.yo +6 -10
  193. package/out/types/src/evaluator/calls/module-type.d.ts +0 -11
  194. package/out/types/src/evaluator/types/module.d.ts +0 -19
@@ -1,200 +1,185 @@
1
1
  //! Doubly-linked list with O(1) push/pop at both ends.
2
-
3
2
  /// Error variants for LinkedList operations.
4
3
  LinkedListError :: enum(
5
4
  /// Index is out of bounds for the current length.
6
- IndexOutOfBounds(index: usize, length: usize),
5
+ IndexOutOfBounds(index : usize, length : usize),
7
6
  /// Attempted to access an element from an empty list.
8
7
  EmptyList
9
8
  );
10
-
11
9
  /// Internal node for the linked list. Reference-counted via `object`.
12
- Node :: (fn(comptime(T): Type) -> comptime(Type))
10
+ Node :: (fn(comptime(T) : Type) -> comptime(Type))(
13
11
  object(
14
12
  value : T,
15
13
  next : Option(Self),
16
14
  prev : Option(Self)
17
15
  )
18
- ;
19
-
16
+ );
20
17
  /// Doubly-linked list with O(1) push/pop at both ends.
21
- LinkedList :: (fn(comptime(T): Type) -> comptime(Type))
18
+ LinkedList :: (fn(comptime(T) : Type) -> comptime(Type))(
22
19
  object(
23
20
  head : Option(Node(T)),
24
21
  tail : Option(Node(T)),
25
22
  length : usize
26
23
  )
27
- ;
28
-
29
- impl(forall(T : Type), LinkedList(T),
24
+ );
25
+ impl(
26
+ forall(T : Type),
27
+ LinkedList(T),
30
28
  /**
31
- * Create a new empty LinkedList
32
- */
29
+ * Create a new empty LinkedList
30
+ */
33
31
  new : (fn() -> Self)(
34
32
  Self(
35
- head: .None,
36
- tail: .None,
37
- length: usize(0)
33
+ head :.None,
34
+ tail :.None,
35
+ length : usize(0)
38
36
  )
39
37
  ),
40
-
41
38
  /**
42
- * Get the number of elements in the list
43
- */
44
- len : (fn(self: Self) -> usize)(
39
+ * Get the number of elements in the list
40
+ */
41
+ len : (fn(self : Self) -> usize)(
45
42
  self.length
46
43
  ),
47
-
48
44
  /**
49
- * Check if the list is empty
50
- */
51
- is_empty : (fn(self: Self) -> bool)(
52
- (self.length == usize(0))
45
+ * Check if the list is empty
46
+ */
47
+ is_empty : (fn(self : Self) -> bool)(
48
+ self.length == usize(0)
53
49
  ),
54
-
55
50
  /**
56
- * Push an element to the front of the list
57
- * O(1) time complexity
58
- */
59
- push_front : (fn(self: Self, value: T) -> unit)(
60
- {
61
- new_node := Node(T)(
62
- value: value,
63
- next: self.head,
64
- prev: .None
65
- );
66
-
67
- match(self.head,
68
- .None => {
69
- self.tail = .Some(new_node);
70
- },
71
- .Some(old_head) => {
72
- old_head.prev = .Some(new_node);
73
- }
74
- );
75
-
76
- self.head = .Some(new_node);
77
- self.length = (self.length + usize(1));
78
- }
79
- ),
80
-
51
+ * Push an element to the front of the list
52
+ * O(1) time complexity
53
+ */
54
+ push_front : (fn(self : Self, value : T) -> unit)({
55
+ new_node := Node(T)(
56
+ value : value,
57
+ next : self.head,
58
+ prev :.None
59
+ );
60
+ match(
61
+ self.head,
62
+ .None => {
63
+ self.tail =.Some(new_node);
64
+ },
65
+ .Some(old_head) => {
66
+ old_head.prev =.Some(new_node);
67
+ }
68
+ );
69
+ self.head =.Some(new_node);
70
+ self.length = (self.length + usize(1));
71
+ }),
81
72
  /**
82
- * Push an element to the back of the list
83
- * O(1) time complexity
84
- */
85
- push_back : (fn(self: Self, value: T) -> unit)(
86
- {
87
- new_node := Node(T)(
88
- value: value,
89
- next: .None,
90
- prev: self.tail
91
- );
92
-
93
- match(self.tail,
94
- .None => {
95
- self.head = .Some(new_node);
96
- },
97
- .Some(old_tail) => {
98
- old_tail.next = .Some(new_node);
99
- }
100
- );
101
-
102
- self.tail = .Some(new_node);
103
- self.length = (self.length + usize(1));
104
- }
105
- ),
106
-
73
+ * Push an element to the back of the list
74
+ * O(1) time complexity
75
+ */
76
+ push_back : (fn(self : Self, value : T) -> unit)({
77
+ new_node := Node(T)(
78
+ value : value,
79
+ next :.None,
80
+ prev : self.tail
81
+ );
82
+ match(
83
+ self.tail,
84
+ .None => {
85
+ self.head =.Some(new_node);
86
+ },
87
+ .Some(old_tail) => {
88
+ old_tail.next =.Some(new_node);
89
+ }
90
+ );
91
+ self.tail =.Some(new_node);
92
+ self.length = (self.length + usize(1));
93
+ }),
107
94
  /**
108
- * Remove and return the element from the front
109
- * O(1) time complexity
110
- */
111
- pop_front : (fn(self: Self) -> Option(T))(
112
- match(self.head,
113
- .None => .None,
95
+ * Remove and return the element from the front
96
+ * O(1) time complexity
97
+ */
98
+ pop_front : (fn(self : Self) -> Option(T))(
99
+ match(
100
+ self.head,
101
+ .None =>.None,
114
102
  .Some(old_head) => {
115
103
  value := old_head.value;
116
104
  new_head_opt := old_head.next;
117
-
118
- match(new_head_opt,
105
+ match(
106
+ new_head_opt,
119
107
  .None => {
120
- self.head = .None;
121
- self.tail = .None;
108
+ self.head =.None;
109
+ self.tail =.None;
122
110
  },
123
111
  .Some(new_head) => {
124
- new_head.prev = .None;
125
- self.head = .Some(new_head);
112
+ new_head.prev =.None;
113
+ self.head =.Some(new_head);
126
114
  }
127
115
  );
128
-
129
116
  self.length = (self.length - usize(1));
130
117
  .Some(value)
131
118
  }
132
119
  )
133
120
  ),
134
-
135
121
  /**
136
- * Remove and return the element from the back
137
- * O(1) time complexity
138
- */
139
- pop_back : (fn(self: Self) -> Option(T))(
140
- match(self.tail,
141
- .None => .None,
122
+ * Remove and return the element from the back
123
+ * O(1) time complexity
124
+ */
125
+ pop_back : (fn(self : Self) -> Option(T))(
126
+ match(
127
+ self.tail,
128
+ .None =>.None,
142
129
  .Some(old_tail) => {
143
130
  value := old_tail.value;
144
131
  new_tail_opt := old_tail.prev;
145
-
146
- match(new_tail_opt,
132
+ match(
133
+ new_tail_opt,
147
134
  .None => {
148
- self.head = .None;
149
- self.tail = .None;
135
+ self.head =.None;
136
+ self.tail =.None;
150
137
  },
151
138
  .Some(new_tail) => {
152
- new_tail.next = .None;
153
- self.tail = .Some(new_tail);
139
+ new_tail.next =.None;
140
+ self.tail =.Some(new_tail);
154
141
  }
155
142
  );
156
-
157
143
  self.length = (self.length - usize(1));
158
144
  .Some(value)
159
145
  }
160
146
  )
161
147
  ),
162
-
163
148
  /**
164
- * Get reference to the front element without removing it
165
- */
166
- front : (fn(self: Self) -> Option(T))(
167
- match(self.head,
168
- .None => .None,
169
- .Some(head_node) => .Some(head_node.value)
149
+ * Get reference to the front element without removing it
150
+ */
151
+ front : (fn(self : Self) -> Option(T))(
152
+ match(
153
+ self.head,
154
+ .None =>.None,
155
+ .Some(head_node) =>.Some(head_node.value)
170
156
  )
171
157
  ),
172
-
173
158
  /**
174
- * Get reference to the back element without removing it
175
- */
176
- back : (fn(self: Self) -> Option(T))(
177
- match(self.tail,
178
- .None => .None,
179
- .Some(tail_node) => .Some(tail_node.value)
159
+ * Get reference to the back element without removing it
160
+ */
161
+ back : (fn(self : Self) -> Option(T))(
162
+ match(
163
+ self.tail,
164
+ .None =>.None,
165
+ .Some(tail_node) =>.Some(tail_node.value)
180
166
  )
181
167
  ),
182
-
183
168
  /**
184
- * Get element at a specific index
185
- * O(n) time complexity
186
- */
187
- get : (fn(self: Self, index: usize) -> Option(T))(
169
+ * Get element at a specific index
170
+ * O(n) time complexity
171
+ */
172
+ get : (fn(self : Self, index : usize) -> Option(T))(
188
173
  cond(
189
- (index >= self.length) => .None,
174
+ (index >= self.length) =>.None,
190
175
  true => {
191
176
  current_opt := self.head;
192
177
  i := usize(0);
193
-
194
178
  while(i < index, i = (i + usize(1)), {
195
- match(current_opt,
179
+ match(
180
+ current_opt,
196
181
  .None => {
197
- return .None;
182
+ return(.None);
198
183
  },
199
184
  .Some(current) => {
200
185
  current_opt = current.next;
@@ -202,22 +187,21 @@ impl(forall(T : Type), LinkedList(T),
202
187
  }
203
188
  );
204
189
  });
205
-
206
- match(current_opt,
207
- .None => .None,
208
- .Some(node) => .Some(node.value)
190
+ match(
191
+ current_opt,
192
+ .None =>.None,
193
+ .Some(node) =>.Some(node.value)
209
194
  )
210
195
  }
211
196
  )
212
197
  ),
213
-
214
198
  /**
215
- * Insert element at a specific index
216
- * O(n) time complexity
217
- */
218
- insert : (fn(self: Self, index: usize, value: T) -> Result(unit, LinkedListError))(
199
+ * Insert element at a specific index
200
+ * O(n) time complexity
201
+ */
202
+ insert : (fn(self : Self, index : usize, value : T) -> Result(unit, LinkedListError))(
219
203
  cond(
220
- (index > self.length) => .Err(.IndexOutOfBounds(index: index, length: self.length)),
204
+ (index > self.length) =>.Err(.IndexOutOfBounds(index : index, length : self.length)),
221
205
  (index == usize(0)) => {
222
206
  self.push_front(value);
223
207
  .Ok(())
@@ -229,40 +213,37 @@ impl(forall(T : Type), LinkedList(T),
229
213
  true => {
230
214
  current_opt := self.head;
231
215
  i := usize(0);
232
-
233
216
  while(i < index, i = (i + usize(1)), {
234
- match(current_opt,
217
+ match(
218
+ current_opt,
235
219
  .None => {
236
- return .Err(.IndexOutOfBounds(index: index, length: self.length));
220
+ return(.Err(.IndexOutOfBounds(index : index, length : self.length)));
237
221
  },
238
222
  .Some(current) => {
239
223
  current_opt = current.next;
240
224
  }
241
225
  );
242
226
  });
243
-
244
- match(current_opt,
245
- .None => .Err(.IndexOutOfBounds(index: index, length: self.length)),
227
+ match(
228
+ current_opt,
229
+ .None =>.Err(.IndexOutOfBounds(index : index, length : self.length)),
246
230
  .Some(current) => {
247
231
  prev_opt := current.prev;
248
-
249
232
  new_node := Node(T)(
250
- value: value,
251
- next: .Some(current),
252
- prev: prev_opt
233
+ value : value,
234
+ next :.Some(current),
235
+ prev : prev_opt
253
236
  );
254
-
255
- current.prev = .Some(new_node);
256
-
257
- match(prev_opt,
237
+ current.prev =.Some(new_node);
238
+ match(
239
+ prev_opt,
258
240
  .None => {
259
- self.head = .Some(new_node);
241
+ self.head =.Some(new_node);
260
242
  },
261
243
  .Some(prev_node) => {
262
- prev_node.next = .Some(new_node);
244
+ prev_node.next =.Some(new_node);
263
245
  }
264
246
  );
265
-
266
247
  self.length = (self.length + usize(1));
267
248
  .Ok(())
268
249
  }
@@ -270,47 +251,48 @@ impl(forall(T : Type), LinkedList(T),
270
251
  }
271
252
  )
272
253
  ),
273
-
274
254
  /**
275
- * Remove element at a specific index
276
- * O(n) time complexity
277
- */
278
- remove : (fn(self: Self, index: usize) -> Result(T, LinkedListError))(
255
+ * Remove element at a specific index
256
+ * O(n) time complexity
257
+ */
258
+ remove : (fn(self : Self, index : usize) -> Result(T, LinkedListError))(
279
259
  cond(
280
- (index >= self.length) => .Err(.IndexOutOfBounds(index: index, length: self.length)),
260
+ (index >= self.length) =>.Err(.IndexOutOfBounds(index : index, length : self.length)),
281
261
  (index == usize(0)) =>
282
- match(self.pop_front(),
283
- .Some(value) => .Ok(value),
284
- .None => .Err(.EmptyList)
262
+ match(
263
+ self.pop_front(),
264
+ .Some(value) =>.Ok(value),
265
+ .None =>.Err(.EmptyList)
285
266
  ),
286
267
  (index == (self.length - usize(1))) =>
287
- match(self.pop_back(),
288
- .Some(value) => .Ok(value),
289
- .None => .Err(.EmptyList)
268
+ match(
269
+ self.pop_back(),
270
+ .Some(value) =>.Ok(value),
271
+ .None =>.Err(.EmptyList)
290
272
  ),
291
273
  true => {
292
274
  current_opt := self.head;
293
275
  i := usize(0);
294
-
295
276
  while(i < index, i = (i + usize(1)), {
296
- match(current_opt,
277
+ match(
278
+ current_opt,
297
279
  .None => {
298
- return .Err(.IndexOutOfBounds(index: index, length: self.length));
280
+ return(.Err(.IndexOutOfBounds(index : index, length : self.length)));
299
281
  },
300
282
  .Some(current) => {
301
283
  current_opt = current.next;
302
284
  }
303
285
  );
304
286
  });
305
-
306
- match(current_opt,
307
- .None => .Err(.IndexOutOfBounds(index: index, length: self.length)),
287
+ match(
288
+ current_opt,
289
+ .None =>.Err(.IndexOutOfBounds(index : index, length : self.length)),
308
290
  .Some(node_to_remove) => {
309
291
  value := node_to_remove.value;
310
292
  prev_opt := node_to_remove.prev;
311
293
  next_opt := node_to_remove.next;
312
-
313
- match(prev_opt,
294
+ match(
295
+ prev_opt,
314
296
  .Some(prev_node) => {
315
297
  prev_node.next = next_opt;
316
298
  },
@@ -318,8 +300,8 @@ impl(forall(T : Type), LinkedList(T),
318
300
  self.head = next_opt;
319
301
  }
320
302
  );
321
-
322
- match(next_opt,
303
+ match(
304
+ next_opt,
323
305
  .Some(next_node) => {
324
306
  next_node.prev = prev_opt;
325
307
  },
@@ -327,7 +309,6 @@ impl(forall(T : Type), LinkedList(T),
327
309
  self.tail = prev_opt;
328
310
  }
329
311
  );
330
-
331
312
  self.length = (self.length - usize(1));
332
313
  .Ok(value)
333
314
  }
@@ -335,154 +316,155 @@ impl(forall(T : Type), LinkedList(T),
335
316
  }
336
317
  )
337
318
  ),
338
-
339
319
  /**
340
- * Clear all elements from the list
341
- */
342
- clear : (fn(self: Self) -> unit)(
343
- {
344
- while((self.length > usize(0)), {
345
- _ := self.pop_front();
346
- });
347
- }
348
- ),
349
-
320
+ * Clear all elements from the list
321
+ */
322
+ clear : (fn(self : Self) -> unit)({
323
+ while(self.length > usize(0), {
324
+ _ := self.pop_front();
325
+ });
326
+ }),
350
327
  /**
351
- * Check if the list contains a value
352
- * O(n) time complexity
353
- */
354
- contains : (fn(
355
- self: Self,
356
- value: T,
357
- where(T <: Eq(T))
358
- ) -> bool)(
359
- {
360
- current_opt := self.head;
361
- i := usize(0);
362
-
363
- while(i < self.length, i = (i + usize(1)), {
364
- match(current_opt,
365
- .None => {
366
- return false;
367
- },
368
- .Some(current) => {
369
- cond(
370
- (current.value == value) => {
371
- return true;
372
- },
373
- true => {
374
- current_opt = current.next;
375
- }
376
- );
377
- }
378
- );
379
- });
380
-
381
- false
382
- }
383
- ),
384
-
328
+ * Check if the list contains a value
329
+ * O(n) time complexity
330
+ */
331
+ contains : (
332
+ fn(
333
+ self : Self,
334
+ value : T,
335
+ where(T <: Eq(T))
336
+ ) -> bool
337
+ )({
338
+ current_opt := self.head;
339
+ i := usize(0);
340
+ while(i < self.length, i = (i + usize(1)), {
341
+ match(
342
+ current_opt,
343
+ .None => {
344
+ return(false);
345
+ },
346
+ .Some(current) => {
347
+ cond(
348
+ (current.value == value) => {
349
+ return(true);
350
+ },
351
+ true => {
352
+ current_opt = current.next;
353
+ }
354
+ );
355
+ }
356
+ );
357
+ });
358
+ false
359
+ }),
385
360
  /**
386
- * Reverse the list in place
387
- * O(n) time complexity
388
- */
389
- reverse : (fn(self: Self) -> unit)(
390
- {
391
- current_opt := self.head;
392
- i := usize(0);
393
-
394
- while(i < self.length, i = (i + usize(1)), {
395
- match(current_opt,
396
- .None => {
397
- return;
398
- },
399
- .Some(current) => {
400
- temp := current.next;
401
- current.next = current.prev;
402
- current.prev = temp;
403
- current_opt = temp;
404
- }
405
- );
406
- });
407
-
408
- temp_head := self.head;
409
- self.head = self.tail;
410
- self.tail = temp_head;
411
- }
412
- )
361
+ * Reverse the list in place
362
+ * O(n) time complexity
363
+ */
364
+ reverse : (fn(self : Self) -> unit)({
365
+ current_opt := self.head;
366
+ i := usize(0);
367
+ while(i < self.length, i = (i + usize(1)), {
368
+ match(
369
+ current_opt,
370
+ .None => {
371
+ return;
372
+ },
373
+ .Some(current) => {
374
+ temp := current.next;
375
+ current.next = current.prev;
376
+ current.prev = temp;
377
+ current_opt = temp;
378
+ }
379
+ );
380
+ });
381
+ temp_head := self.head;
382
+ self.head = self.tail;
383
+ self.tail = temp_head;
384
+ })
413
385
  );
414
-
415
- impl(forall(T : Type), LinkedList(T), Dispose(
416
- /**
386
+ impl(
387
+ forall(T : Type),
388
+ LinkedList(T),
389
+ Dispose(
390
+ /**
417
391
  * RAII destructor - automatically called when LinkedList goes out of scope
418
392
  */
419
- dispose : (fn(self: Self) -> unit)(
420
- self.clear()
393
+ dispose : (fn(self : Self) -> unit)(
394
+ self.clear()
395
+ )
421
396
  )
422
- ));
423
-
397
+ );
424
398
  /**
425
- * Value iterator for LinkedList - yields elements by value (T)
426
- * Traverses the linked list following node.next pointers.
427
- */
399
+ * Value iterator for LinkedList - yields elements by value (T)
400
+ * Traverses the linked list following node.next pointers.
401
+ */
428
402
  LinkedListIter :: (fn(comptime(T) : Type) -> comptime(Type))(
429
403
  struct(
430
404
  _current : Option(Node(T))
431
405
  )
432
406
  );
433
-
434
- impl(forall(T : Type), LinkedListIter(T), Iterator(
435
- Item : T,
436
- next : (fn(self : *(Self)) -> Option(T))(
437
- match(self._current,
438
- .None => .None,
439
- .Some(node) => {
440
- self._current = node.next;
441
- .Some(node.value)
442
- }
407
+ impl(
408
+ forall(T : Type),
409
+ LinkedListIter(T),
410
+ Iterator(
411
+ Item : T,
412
+ next : (fn(self : *(Self)) -> Option(T))(
413
+ match(
414
+ self._current,
415
+ .None =>.None,
416
+ .Some(node) => {
417
+ self._current = node.next;
418
+ .Some(node.value)
419
+ }
420
+ )
443
421
  )
444
422
  )
445
- ));
446
-
447
- impl(forall(T : Type), LinkedList(T),
423
+ );
424
+ impl(
425
+ forall(T : Type),
426
+ LinkedList(T),
448
427
  into_iter : (fn(self : Self) -> LinkedListIter(T))(
449
- LinkedListIter(T)(_current: self.head)
428
+ LinkedListIter(T)(_current : self.head)
450
429
  )
451
430
  );
452
-
453
431
  /**
454
- * Pointer iterator for LinkedList - yields pointers to elements (*(T))
455
- * Yields &(node.value) for each node. Pointers are valid as long as
456
- * the list is not modified during iteration.
457
- */
432
+ * Pointer iterator for LinkedList - yields pointers to elements (*(T))
433
+ * Yields &(node.value) for each node. Pointers are valid as long as
434
+ * the list is not modified during iteration.
435
+ */
458
436
  LinkedListIterPtr :: (fn(comptime(T) : Type) -> comptime(Type))(
459
437
  struct(
460
438
  _current : Option(Node(T))
461
439
  )
462
440
  );
463
-
464
- impl(forall(T : Type), LinkedListIterPtr(T), Iterator(
465
- Item : *(T),
466
- next : (fn(self : *(Self)) -> Option(*(T)))(
467
- match(self._current,
468
- .None => .None,
469
- .Some(node) => {
470
- self._current = node.next;
471
- .Some(&(node.value))
472
- }
441
+ impl(
442
+ forall(T : Type),
443
+ LinkedListIterPtr(T),
444
+ Iterator(
445
+ Item : *(T),
446
+ next : (fn(self : *(Self)) -> Option(*(T)))(
447
+ match(
448
+ self._current,
449
+ .None =>.None,
450
+ .Some(node) => {
451
+ self._current = node.next;
452
+ .Some(&(node.value))
453
+ }
454
+ )
473
455
  )
474
456
  )
475
- ));
476
-
477
- impl(forall(T : Type), LinkedList(T),
457
+ );
458
+ impl(
459
+ forall(T : Type),
460
+ LinkedList(T),
478
461
  iter : (fn(self : *(Self)) -> LinkedListIterPtr(T))(
479
- LinkedListIterPtr(T)(_current: self.*.head)
462
+ LinkedListIterPtr(T)(_current : self.*.head)
480
463
  )
481
464
  );
482
-
483
- export
465
+ export(
484
466
  LinkedList,
485
467
  LinkedListError,
486
468
  LinkedListIter,
487
469
  LinkedListIterPtr
488
- ;
470
+ );