-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathset.d.lua
More file actions
582 lines (545 loc) · 14 KB
/
Copy pathset.d.lua
File metadata and controls
582 lines (545 loc) · 14 KB
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
---@meta _
---
---A set class for creating, combining, and querying unique values.
---
---## Usage
---
---```lua
---Set = mods.set
---
---s = Set({ "a" })
---print(s:contains("a")) --> true
---```
---
---@class mods.Set<T>:table<T,true>
---@operator add(mods.Set):mods.Set
---@operator band(mods.Set):mods.Set
---@operator bor(mods.Set):mods.Set
---@operator bxor(mods.Set):mods.Set
---@operator sub(mods.Set):mods.Set
---@overload fun(t?:any[]|mods.List):mods.Set
local Set = {}
Set.__index = Set
---
---Add an element to the set.
---
---```lua
---s = Set({ "a" }):add("b") --> s contains "a", "b"
---```
---
---@section Mutation
---@generic T:mods.Set|table<any,true>
---@param self T Current set.
---@param v any Value to add.
---@return T self Current set.
function Set:add(v) end
---
---Remove all elements from the set.
---
---```lua
---s = Set({ "a", "b" }):clear() --> s is empty
---```
---
---@section Mutation
---@generic T:mods.Set|table<any,true>
---@param self T Current set.
---@return T self Current set.
function Set:clear() end
---
---Remove elements found in another set (in place).
---
---```lua
---s = Set({ "a", "b" }):difference_update(Set({ "b" })) --> s contains "a"
---```
---
---@section Mutation
---@generic T:mods.Set|table<any,true>
---@param self T Current set.
---@param set T|mods.List Other set/list.
---@return T self Current set.
function Set:difference_update(set) end
---
---Keep only elements common to both sets (in place).
---
---```lua
---s = Set({ "a", "b" }):intersection_update(Set({ "b", "c" }))
-----> s contains "b"
---```
---
---@section Mutation
---@generic T:mods.Set|table<any,true>
---@param self T Current set.
---@param set T|mods.List Other set/list.
---@return T self Current set.
function Set:intersection_update(set) end
---
---Remove and return an arbitrary element.
---
---```lua
---v = Set({ "a", "b" }):pop() --> v is either "a" or "b"
---```
---
---@section Mutation
---@param self mods.Set|table<any,true> Current set.
---@return any removedValue Removed value, or `nil` when the set is empty.
function Set:pop() end
---
---Update the set with elements not shared by both (in place).
---
---```lua
---s = Set({ "a", "b" }):symmetric_difference_update(Set({ "b", "c" }))
-----> s contains "a", "c"
---```
---
---@section Mutation
---@generic T:mods.Set|table<any,true>
---@param self T Current set.
---@param set T|mods.List Other set/list.
---@return T self Current set.
function Set:symmetric_difference_update(set) end
---
---Add all elements from another set (in place).
---
---```lua
---s = Set({ "a" }):update(Set({ "b" })) --> s contains "a", "b"
---```
---
---@section Mutation
---@generic T:mods.Set|table<any,true>
---@param self T Current set.
---@param set T|mods.List Other set/list.
---@return T self Current set.
function Set:update(set) end
---
---Return a shallow copy of the set.
---
---```lua
---c = Set({ "a" }):copy() --> c is a new set with "a"
---```
---
---@section Set Operations
---@param self mods.Set|table<any,true> Current set.
---@return mods.Set set New set.
---@nodiscard
function Set:copy() end
---
---Check whether a value is present in the set without following the metatable.
---
---```lua
---s = Set({ "a", "b", "c" })
---print(s:has("a")) --> true
---print(s:has("__index")) --> false
---```
---
---@section Set Operations
---@param self mods.Set|table<any,true> Current set.
---@param v any Value to look up.
---@return boolean present Whether the value is present.
---@nodiscard
function Set:has(v) end
---
---Return elements in this set but not in another.
---
---```lua
---d = Set({ "a", "b" }):difference(Set({ "b" })) --> d contains "a"
---```
---
---> [!NOTE]
--->
---> `difference` is also available as the `__sub` (`-`) operator.
---> `a:difference(b)` is equivalent to `a - b`.
---
---@section Set Operations
---@param self mods.Set|table<any,true> Current set.
---@param t mods.Set|mods.List|table<any,true> Other set/list.
---@return mods.Set set New set.
---@nodiscard
function Set:difference(t) end
---
---Return elements common to both sets.
---
---```lua
---i = Set({ "a", "b" }):intersection(Set({ "b", "c" })) --> i contains "b"
---```
---
---> [!NOTE]
--->
---> `intersection` is also available as `__band` (`&`) on Lua 5.3+.
---
---@section Set Operations
---@param self mods.Set|table<any,true> Current set.
---@param t mods.Set|mods.List|table<any,true> Other set/list.
---@return mods.Set set New set.
---@nodiscard
function Set:intersection(t) end
---
---Remove an element if present, do nothing otherwise.
---
---```lua
---s = Set({ "a", "b" }):remove("b") --> s contains "a"
---```
---
---@section Set Operations
---@generic T:mods.Set|table<any,true>
---@param self T Current set.
---@param v any Value to remove.
---@return T self Current set.
function Set:remove(v) end
---
---Return elements not shared by both sets.
---
---```lua
---d = Set({ "a", "b" }):symmetric_difference(Set({ "b", "c" }))
-----> d contains "a", "c"
---```
---
---> [!NOTE]
--->
---> `symmetric_difference` is also available as `__bxor` (`^`) on Lua 5.3+.
---
---@section Set Operations
---@param self mods.Set|table<any,true> Current set.
---@param t mods.Set|mods.List|table<any,true> Other set/list.
---@return mods.Set set New set.
---@nodiscard
function Set:symmetric_difference(t) end
---
---Return a new set with all elements from both.
---
---```lua
---s = Set({ "a" }):union(Set({ "b" })) --> s contains "a", "b"
---```
---
---> [!NOTE]
--->
---> `union` is available as `__add` (`+`) and `__bor` (`|`) on Lua 5.3+.
---> `a:union(b)` is equivalent to `a + b` and `a | b`.
---
---@section Set Operations
---@param self mods.Set|table<any,true> Current set.
---@param t mods.Set|mods.List|table<any,true> Other set/list.
---@return mods.Set set New set.
---@nodiscard
function Set:union(t) end
---
---Return true if sets have no elements in common.
---
---```lua
---ok = Set({ "a" }):isdisjoint(Set({ "b" })) --> true
---```
---
---@section Predicates
---@generic T:mods.Set|table<any,true>
---@param self T Current set.
---@param set T|mods.List Other set/list.
---@return boolean isDisjoint True when sets have no elements in common.
---@nodiscard
function Set:isdisjoint(set) end
---
---Return true when both sets contain exactly the same members.
---
---```lua
---a = Set({ "a", "b" })
---b = Set({ "b", "a" })
---ok = a:equals(b) --> true
---```
---
---> [!NOTE]
--->
---> `equals` is also available as the `__eq` (`==`) operator.
---> `a:equals(b)` is equivalent to `a == b`.
---
---@section Predicates
---@param self mods.Set|table<any,true> Current set.
---@param t mods.Set|mods.List|table<any,true> Other set/list.
---@return boolean isEqual True when both sets contain the same members.
---@nodiscard
function Set:equals(t) end
---
---Return true if the set has no elements.
---
---```lua
---empty = Set({}):isempty() --> true
---```
---
---@section Predicates
---@param self mods.Set|table<any,true> Current set.
---@return boolean isEmpty True when the set has no elements.
---@nodiscard
function Set:isempty() end
---
---Return true if all elements of this set are also in another set.
---
---```lua
---ok = Set({ "a" }):issubset(Set({ "a", "b" })) --> true
---```
---
---> [!NOTE]
--->
---> `issubset` is also available as the `__le` (`<=`) operator.
---> `a:issubset(b)` is equivalent to `a <= b`.
---
---@section Predicates
---@param self mods.Set|table<any,true> Current set.
---@param t mods.Set|mods.List|table<any,true> Other set/list.
---@return boolean isSubset True when every element of `self` exists in `set`.
---@nodiscard
function Set:issubset(t) end
---
---Return true if this set contains all elements of another set.
---
---```lua
---ok = Set({ "a", "b" }):issuperset(Set({ "a" })) --> true
---```
---
---@section Predicates
---@param self mods.Set|table<any,true> Current set.
---@param t mods.Set|mods.List|table<any,true> Other set/list.
---@return boolean isSuperset True when `self` contains every element of `set`.
---@nodiscard
function Set:issuperset(t) end
---
---Return true if the set contains `v`.
---
---```lua
---ok = Set({ "a", "b" }):contains("a") --> true
---ok = Set({ "a", "b" }):contains("z") --> false
---```
---
---@section Queries
---@param self mods.Set|table<any,true> Current set.
---@param v any Value to check.
---@return boolean isPresent True when `v` is present in the set.
---@nodiscard
function Set:contains(v) end
---
---Return the number of elements in the set.
---
---```lua
---n = Set({ "a", "b" }):len() --> 2
---```
---
---@section Queries
---@param self mods.Set|table<any,true> Current set.
---@return integer count Element count.
---@nodiscard
function Set:len() end
---
---Return a new set by mapping each value.
---
---```lua
---s = Set({ 1, 2 }):map(function(v) return v * 10 end) --> s contains 10, 20
---```
---
---@section Transforms
---@param self mods.Set|table<any,true> Current set.
---@param fn fun(v:any):any Mapping function.
---@return mods.Set set New set.
---@nodiscard
function Set:map(fn) end
---
---Mirror values into a new table as both keys and values.
---
---```lua
---mirrored = Set({ "a", "b" }):mirror() --> { a = "a", b = "b" }
---```
---
---@section Transforms
---@generic K
---@param self table<K,true> Current set.
---@return table<K,K> mirroredValues Table mapping each value to itself.
---@nodiscard
function Set:mirror() end
---
---Return a list of all values in the set.
---
---```lua
---values = Set({ "a", "b" }):values() --> { "a", "b" }
---```
---
---@section Transforms
---@param self mods.Set|table<any,true> Current set.
---@return mods.List values List of set values.
---@nodiscard
function Set:values() end
---
---Render the set as a string.
---
---```lua
---s = Set({ "b", "a", 1 }):tostring() --> '{ 1, "a", "b" }'
---```
---
---@section Transforms
---@param self mods.Set|table<any,true> Current set.
---@return string renderedSet Rendered set string.
---@nodiscard
function Set:tostring() end
---
---Join set values into a string.
---
---```lua
---s = Set({ "b", "a" }):join(", ") --> "a, b"
---s = Set({ "b", "a" }):join(", ", true) --> '"a", "b"'
---```
---
---> [!NOTE]
--->
---Join order is not guaranteed.
---
---@section Transforms
---@param self mods.Set|table<any,true> Current set.
---@param sep? string Optional separator value (defaults to `""`).
---@param quoted? boolean Optional boolean flag (defaults to `false`).
---@return string joined Joined string.
---@nodiscard
function Set:join(sep, quoted) end
---
---Return the union of two sets using `+`.
---
---```lua
---a = Set({ "a", "b" })
---b = Set({ "b", "c" })
---u = a + b --> { a = true, b = true, c = true }
---```
---
---> [!NOTE]
--->
---> `__add` is the operator form of `:union(set)`.
---
---@section Metamethods
---@param self mods.Set Current set.
---@param t mods.Set|mods.List|table<any,true> Other set/list.
---@return mods.Set set New set.
function Set.__add(self, t) end
---
---Return the union of two sets using `|`.
---
---```lua
---a = Set({ "a", "b" })
---b = Set({ "b", "c" })
---u = a | b --> { a = true, b = true, c = true }
---```
---
---> [!NOTE]
--->
---> `__bor` is the operator form of `:union(set)` on Lua 5.3+.
---
---@section Metamethods
---@param self mods.Set Current set.
---@param t mods.Set|mods.List|table<any,true> Other set/list.
---@return mods.Set set New set.
function Set.__bor(self, t) end
---
---Return the intersection of two sets using `&`.
---
---```lua
---a = Set({ "a", "b" })
---b = Set({ "b", "c" })
---i = a & b --> { b = true }
---```
---
---> [!NOTE]
--->
---> `__band` is the operator form of `:intersection(set)` on Lua 5.3+.
---
---@section Metamethods
---@param self mods.Set Current set.
---@param t mods.Set|mods.List|table<any,true> Other set/list.
---@return mods.Set set New set.
function Set.__band(self, t) end
---
---Return elements present in exactly one set using `^`.
---
---```lua
---a = Set({ "a", "b" })
---b = Set({ "b", "c" })
---d = a ^ b --> { a = true, c = true }
---```
---
---> [!NOTE]
--->
---> `__bxor` is the operator form of `:symmetric_difference(set)` on Lua 5.3+.
---
---@section Metamethods
---@param self mods.Set Current set.
---@param t mods.Set|mods.List|table<any,true> Other set/list.
---@return mods.Set set New set.
function Set.__bxor(self, t) end
---
---Return true if both sets contain exactly the same members using `==`.
---
---```lua
---ok = Set({ "a", "b" }) == Set({ "b", "a" }) --> true
---```
---
---> [!NOTE]
--->
---> `__eq` is the operator form of `:equals(set)`.
---
---@section Metamethods
---@param self mods.Set Current set.
---@param t mods.Set|mods.List|table<any,true> Other set/list.
---@return boolean isEqual True when both sets contain the same members.
function Set.__eq(self, t) end
---
---Return true if the left set is a subset of the right set using `<=`.
---
---```lua
---a = Set({ "a" })
---b = Set({ "a", "b" })
---ok = a <= b --> true
---```
---
---> [!NOTE]
--->
---> `__le` is the operator form of `:issubset(set)`.
---
---@section Metamethods
---@param self mods.Set Current set.
---@param t mods.Set|mods.List|table<any,true> Other set/list.
---@return boolean isSubset True when `self` is a subset of `set`.
function Set.__le(self, t) end
---
---Return true if the left set is a proper subset of the right set using `<`.
---
---```lua
---a = Set({ "a" })
---b = Set({ "a", "b" })
---ok = a < b --> true
---```
---
---@section Metamethods
---@param self mods.Set Current set.
---@param set mods.Set|table<any,true> Other set.
---@return boolean isProperSubset True when `self` is a proper subset of `set`.
function Set.__lt(self, set) end
---
---Return the difference of two sets using `-`.
---
---```lua
---a = Set({ "a", "b" })
---b = Set({ "b", "c" })
---d = a - b --> { a = true }
---```
---
---> [!NOTE]
--->
---> `__sub` is the operator form of `:difference(set)`.
---
---@section Metamethods
---@param self mods.Set Current set.
---@param set mods.Set|table<any,true> Other set.
---@return mods.Set set New set.
function Set.__sub(self, set) end
---
---Render the set via `tostring(set)`.
---
---```lua
---s = tostring(Set({ "b", "a", 1 })) --> '{ 1, "a", "b" }'
---```
---
---@section Metamethods
---@param self mods.Set Current set.
---@return string renderedSet Rendered set string.
function Set.__tostring(self) end
return Set