@oscarpalmer/atoms 0.192.0 → 0.193.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.
Files changed (130) hide show
  1. package/dist/index.d.mts +25 -23
  2. package/dist/index.mjs +30 -31
  3. package/dist/queue.d.mts +25 -23
  4. package/dist/queue.mjs +27 -28
  5. package/package.json +3 -4
  6. package/src/array/difference.ts +0 -73
  7. package/src/array/exists.ts +0 -93
  8. package/src/array/filter.ts +0 -182
  9. package/src/array/find.ts +0 -183
  10. package/src/array/first.ts +0 -196
  11. package/src/array/flatten.ts +0 -20
  12. package/src/array/from.ts +0 -129
  13. package/src/array/get.ts +0 -131
  14. package/src/array/group-by.ts +0 -369
  15. package/src/array/index.ts +0 -26
  16. package/src/array/insert.ts +0 -52
  17. package/src/array/intersection.ts +0 -72
  18. package/src/array/last.ts +0 -194
  19. package/src/array/match.ts +0 -436
  20. package/src/array/move.ts +0 -315
  21. package/src/array/partition.ts +0 -91
  22. package/src/array/push.ts +0 -23
  23. package/src/array/reverse.ts +0 -33
  24. package/src/array/select.ts +0 -260
  25. package/src/array/single.ts +0 -93
  26. package/src/array/slice.ts +0 -335
  27. package/src/array/sort.ts +0 -607
  28. package/src/array/splice.ts +0 -106
  29. package/src/array/swap.ts +0 -322
  30. package/src/array/to-map.ts +0 -371
  31. package/src/array/to-record.ts +0 -351
  32. package/src/array/to-set.ts +0 -80
  33. package/src/array/toggle.ts +0 -79
  34. package/src/array/union.ts +0 -72
  35. package/src/array/unique.ts +0 -67
  36. package/src/array/update.ts +0 -75
  37. package/src/beacon.ts +0 -378
  38. package/src/color/constants.ts +0 -137
  39. package/src/color/index.ts +0 -83
  40. package/src/color/instance.ts +0 -162
  41. package/src/color/misc/alpha.ts +0 -56
  42. package/src/color/misc/format.ts +0 -29
  43. package/src/color/misc/get.ts +0 -210
  44. package/src/color/misc/is.ts +0 -221
  45. package/src/color/misc/state.ts +0 -243
  46. package/src/color/models.ts +0 -389
  47. package/src/color/space/hex.ts +0 -184
  48. package/src/color/space/hsl.ts +0 -174
  49. package/src/color/space/hwb.ts +0 -153
  50. package/src/color/space/rgb.ts +0 -240
  51. package/src/function/assert.ts +0 -174
  52. package/src/function/index.ts +0 -2
  53. package/src/function/limit.ts +0 -83
  54. package/src/function/memoize.ts +0 -202
  55. package/src/function/once.ts +0 -200
  56. package/src/function/retry.ts +0 -175
  57. package/src/function/work.ts +0 -1007
  58. package/src/herald.ts +0 -216
  59. package/src/index.ts +0 -68
  60. package/src/internal/array/callbacks.ts +0 -46
  61. package/src/internal/array/chunk.ts +0 -51
  62. package/src/internal/array/compact.ts +0 -56
  63. package/src/internal/array/find.ts +0 -200
  64. package/src/internal/array/group.ts +0 -42
  65. package/src/internal/array/index-of.ts +0 -182
  66. package/src/internal/array/insert.ts +0 -80
  67. package/src/internal/array/overlap.ts +0 -35
  68. package/src/internal/array/sets.ts +0 -74
  69. package/src/internal/array/shuffle.ts +0 -33
  70. package/src/internal/array/update.ts +0 -52
  71. package/src/internal/function/misc.ts +0 -8
  72. package/src/internal/function/timer.ts +0 -168
  73. package/src/internal/is.ts +0 -244
  74. package/src/internal/math/aggregate.ts +0 -164
  75. package/src/internal/math/misc.ts +0 -28
  76. package/src/internal/number.ts +0 -129
  77. package/src/internal/random.ts +0 -49
  78. package/src/internal/result.ts +0 -92
  79. package/src/internal/sized.ts +0 -25
  80. package/src/internal/string.ts +0 -128
  81. package/src/internal/subscription.ts +0 -264
  82. package/src/internal/value/compare.ts +0 -170
  83. package/src/internal/value/equal.ts +0 -465
  84. package/src/internal/value/get.ts +0 -57
  85. package/src/internal/value/handlers.ts +0 -95
  86. package/src/internal/value/has.ts +0 -118
  87. package/src/internal/value/misc.ts +0 -125
  88. package/src/internal/value/partial.ts +0 -46
  89. package/src/internal/value/set.ts +0 -132
  90. package/src/is.ts +0 -182
  91. package/src/logger.ts +0 -230
  92. package/src/math.ts +0 -281
  93. package/src/models.ts +0 -286
  94. package/src/number.ts +0 -1
  95. package/src/promise/delay.ts +0 -62
  96. package/src/promise/helpers.ts +0 -96
  97. package/src/promise/index.ts +0 -300
  98. package/src/promise/misc.ts +0 -96
  99. package/src/promise/models.ts +0 -195
  100. package/src/promise/timed.ts +0 -91
  101. package/src/query.ts +0 -147
  102. package/src/queue.ts +0 -814
  103. package/src/random.ts +0 -125
  104. package/src/result/index.ts +0 -105
  105. package/src/result/match.ts +0 -124
  106. package/src/result/misc.ts +0 -129
  107. package/src/result/models.ts +0 -83
  108. package/src/result/work/flow.ts +0 -488
  109. package/src/result/work/pipe.ts +0 -496
  110. package/src/sized/map.ts +0 -110
  111. package/src/sized/set.ts +0 -107
  112. package/src/string/case.ts +0 -236
  113. package/src/string/fuzzy.ts +0 -444
  114. package/src/string/index.ts +0 -199
  115. package/src/string/match.ts +0 -80
  116. package/src/string/normalize.ts +0 -205
  117. package/src/string/template.ts +0 -161
  118. package/src/value/clone.ts +0 -319
  119. package/src/value/collection.ts +0 -63
  120. package/src/value/diff.ts +0 -232
  121. package/src/value/freeze.ts +0 -322
  122. package/src/value/handle.ts +0 -3
  123. package/src/value/index.ts +0 -5
  124. package/src/value/merge.ts +0 -278
  125. package/src/value/omit.ts +0 -20
  126. package/src/value/pick.ts +0 -20
  127. package/src/value/shake.ts +0 -45
  128. package/src/value/smush.ts +0 -89
  129. package/src/value/transform.ts +0 -153
  130. package/src/value/unsmush.ts +0 -84
@@ -1,496 +0,0 @@
1
- import {asyncPipe, pipe} from '../../function/work';
2
- import {isError, isOk} from '../../internal/result';
3
- import type {GenericCallback} from '../../models';
4
- import {attempt} from '../index';
5
- import type {Result, UnwrapValue} from '../models';
6
-
7
- // #region Types
8
-
9
- type WrapValue<Value> = Result<UnwrapValue<Value>>;
10
-
11
- // #endregion
12
-
13
- // #region Functions
14
-
15
- // #region Asynchronous
16
-
17
- /**
18
- * Attempt to pipe a value through a function
19
- *
20
- * _Available as `attemptAsyncPipe` and `attemptPipe.async`_
21
- *
22
- * @param initial Initial value
23
- * @returns _Piped_ result
24
- */
25
- export async function attemptAsyncPipe<Initial, Piped>(
26
- initial: GenericCallback | Initial | Promise<Initial> | Result<Initial>,
27
- pipe: (value: UnwrapValue<Initial>) => Piped,
28
- ): Promise<WrapValue<Piped>>;
29
-
30
- /**
31
- * Attempt to pipe a value through a series of functions
32
- *
33
- * _Available as `attemptAsyncPipe` and `attemptPipe.async`_
34
- *
35
- * @param initial Initial value
36
- * @returns _Piped_ result
37
- */
38
- export async function attemptAsyncPipe<Initial, First, Second>(
39
- initial: GenericCallback | Initial | Promise<Initial> | Result<Initial>,
40
- first: (value: UnwrapValue<Initial>) => First,
41
- second: (value: UnwrapValue<First>) => Second,
42
- ): Promise<WrapValue<Second>>;
43
-
44
- /**
45
- * Attempt to pipe a value through a series of functions
46
- *
47
- * _Available as `attemptAsyncPipe` and `attemptPipe.async`_
48
- *
49
- * @param initial Initial value
50
- * @returns _Piped_ result
51
- */
52
- export async function attemptAsyncPipe<Initial, First, Second, Third>(
53
- initial: GenericCallback | Initial | Promise<Initial> | Result<Initial>,
54
- first: (value: UnwrapValue<Initial>) => First,
55
- second: (value: UnwrapValue<First>) => Second,
56
- third: (value: UnwrapValue<Second>) => Third,
57
- ): Promise<WrapValue<Third>>;
58
-
59
- /**
60
- * Attempt to pipe a value through a series of functions
61
- *
62
- * _Available as `attemptAsyncPipe` and `attemptPipe.async`_
63
- *
64
- * @param initial Initial value
65
- * @returns _Piped_ result
66
- */
67
- export async function attemptAsyncPipe<Initial, First, Second, Third, Fourth>(
68
- initial: GenericCallback | Initial | Promise<Initial> | Result<Initial>,
69
- first: (value: UnwrapValue<Initial>) => First,
70
- second: (value: UnwrapValue<First>) => Second,
71
- third: (value: UnwrapValue<Second>) => Third,
72
- fourth: (value: UnwrapValue<Third>) => Fourth,
73
- ): Promise<WrapValue<Fourth>>;
74
-
75
- /**
76
- * Attempt to pipe a value through a series of functions
77
- *
78
- * _Available as `attemptAsyncPipe` and `attemptPipe.async`_
79
- *
80
- * @param initial Initial value
81
- * @returns _Piped_ result
82
- */
83
- export async function attemptAsyncPipe<Initial, First, Second, Third, Fourth, Fifth>(
84
- initial: GenericCallback | Initial | Promise<Initial> | Result<Initial>,
85
- first: (value: UnwrapValue<Initial>) => First,
86
- second: (value: UnwrapValue<First>) => Second,
87
- third: (value: UnwrapValue<Second>) => Third,
88
- fourth: (value: UnwrapValue<Third>) => Fourth,
89
- fifth: (value: UnwrapValue<Fourth>) => Fifth,
90
- ): Promise<WrapValue<Fifth>>;
91
-
92
- /**
93
- * Attempt to pipe a value through a series of functions
94
- *
95
- * _Available as `attemptAsyncPipe` and `attemptPipe.async`_
96
- *
97
- * @param initial Initial value
98
- * @returns _Piped_ result
99
- */
100
- export async function attemptAsyncPipe<Initial, First, Second, Third, Fourth, Fifth, Sixth>(
101
- initial: GenericCallback | Initial | Promise<Initial> | Result<Initial>,
102
- first: (value: UnwrapValue<Initial>) => First,
103
- second: (value: UnwrapValue<First>) => Second,
104
- third: (value: UnwrapValue<Second>) => Third,
105
- fourth: (value: UnwrapValue<Third>) => Fourth,
106
- fifth: (value: UnwrapValue<Fourth>) => Fifth,
107
- sixth: (value: UnwrapValue<Fifth>) => Sixth,
108
- ): Promise<WrapValue<Sixth>>;
109
-
110
- /**
111
- * Attempt to pipe a value through a series of functions
112
- *
113
- * _Available as `attemptAsyncPipe` and `attemptPipe.async`_
114
- *
115
- * @param initial Initial value
116
- * @returns _Piped_ result
117
- */
118
- export async function attemptAsyncPipe<
119
- Initial,
120
- First,
121
- Second,
122
- Third,
123
- Fourth,
124
- Fifth,
125
- Sixth,
126
- Seventh,
127
- >(
128
- initial: GenericCallback | Initial | Promise<Initial> | Result<Initial>,
129
- first: (value: UnwrapValue<Initial>) => First,
130
- second: (value: UnwrapValue<First>) => Second,
131
- third: (value: UnwrapValue<Second>) => Third,
132
- fourth: (value: UnwrapValue<Third>) => Fourth,
133
- fifth: (value: UnwrapValue<Fourth>) => Fifth,
134
- sixth: (value: UnwrapValue<Fifth>) => Sixth,
135
- seventh: (value: UnwrapValue<Sixth>) => Seventh,
136
- ): Promise<WrapValue<Seventh>>;
137
-
138
- /**
139
- * Attempt to pipe a value through a series of functions
140
- *
141
- * _Available as `attemptAsyncPipe` and `attemptPipe.async`_
142
- *
143
- * @param initial Initial value
144
- * @returns _Piped_ result
145
- */
146
- export async function attemptAsyncPipe<
147
- Initial,
148
- First,
149
- Second,
150
- Third,
151
- Fourth,
152
- Fifth,
153
- Sixth,
154
- Seventh,
155
- Eighth,
156
- >(
157
- initial: GenericCallback | Initial | Promise<Initial> | Result<Initial>,
158
- first: (value: UnwrapValue<Initial>) => First,
159
- second: (value: UnwrapValue<First>) => Second,
160
- third: (value: UnwrapValue<Second>) => Third,
161
- fourth: (value: UnwrapValue<Third>) => Fourth,
162
- fifth: (value: UnwrapValue<Fourth>) => Fifth,
163
- sixth: (value: UnwrapValue<Fifth>) => Sixth,
164
- seventh: (value: UnwrapValue<Sixth>) => Seventh,
165
- eighth: (value: UnwrapValue<Seventh>) => Eighth,
166
- ): Promise<WrapValue<Eighth>>;
167
-
168
- /**
169
- * Attempt to pipe a value through a series of functions
170
- *
171
- * _Available as `attemptAsyncPipe` and `attemptPipe.async`_
172
- *
173
- * @param initial Initial value
174
- * @returns _Piped_ result
175
- */
176
- export async function attemptAsyncPipe<
177
- Initial,
178
- First,
179
- Second,
180
- Third,
181
- Fourth,
182
- Fifth,
183
- Sixth,
184
- Seventh,
185
- Eighth,
186
- Ninth,
187
- >(
188
- initial: GenericCallback | Initial | Promise<Initial> | Result<Initial>,
189
- first: (value: UnwrapValue<Initial>) => First,
190
- second: (value: UnwrapValue<First>) => Second,
191
- third: (value: UnwrapValue<Second>) => Third,
192
- fourth: (value: UnwrapValue<Third>) => Fourth,
193
- fifth: (value: UnwrapValue<Fourth>) => Fifth,
194
- sixth: (value: UnwrapValue<Fifth>) => Sixth,
195
- seventh: (value: UnwrapValue<Sixth>) => Seventh,
196
- eighth: (value: UnwrapValue<Seventh>) => Eighth,
197
- ninth: (value: UnwrapValue<Eighth>) => Ninth,
198
- ): Promise<WrapValue<Ninth>>;
199
-
200
- /**
201
- * Attempt to pipe a value through a series of functions
202
- *
203
- * _Available as `attemptAsyncPipe` and `attemptPipe.async`_
204
- *
205
- * @param initial Initial value
206
- * @returns _Piped_ result
207
- */
208
- export async function attemptAsyncPipe<
209
- Initial,
210
- First,
211
- Second,
212
- Third,
213
- Fourth,
214
- Fifth,
215
- Sixth,
216
- Seventh,
217
- Eighth,
218
- Ninth,
219
- Tenth,
220
- >(
221
- initial: GenericCallback | Initial | Promise<Initial> | Result<Initial>,
222
- first: (value: UnwrapValue<Initial>) => First,
223
- second: (value: UnwrapValue<First>) => Second,
224
- third: (value: UnwrapValue<Second>) => Third,
225
- fourth: (value: UnwrapValue<Third>) => Fourth,
226
- fifth: (value: UnwrapValue<Fourth>) => Fifth,
227
- sixth: (value: UnwrapValue<Fifth>) => Sixth,
228
- seventh: (value: UnwrapValue<Sixth>) => Seventh,
229
- eighth: (value: UnwrapValue<Seventh>) => Eighth,
230
- ninth: (value: UnwrapValue<Eighth>) => Ninth,
231
- tenth: (value: UnwrapValue<Ninth>) => Tenth,
232
- ): Promise<WrapValue<Tenth>>;
233
-
234
- /**
235
- * Attempt to pipe a result through a series of functions
236
- *
237
- * _Available as `attemptAsyncPipe` and `attemptPipe.async`_
238
- *
239
- * @param initial Initial result
240
- * @returns _Piped_ result
241
- */
242
- export async function attemptAsyncPipe<Initial>(
243
- initial: GenericCallback | Initial | Promise<Initial> | Result<Initial>,
244
- first?: (value: UnwrapValue<Initial>) => unknown,
245
- ...seconds: Array<(value: unknown) => unknown>
246
- ): Promise<WrapValue<Initial>>;
247
-
248
- export async function attemptAsyncPipe(
249
- initial: unknown,
250
- first?: (value: unknown) => unknown,
251
- ...seconds: Array<(value: unknown) => unknown>
252
- ): Promise<Result<unknown>> {
253
- return attempt.async(() => {
254
- if (isError(initial)) {
255
- throw initial.error;
256
- }
257
-
258
- const value =
259
- typeof initial === 'function'
260
- ? (initial as Function)()
261
- : isOk(initial)
262
- ? initial.value
263
- : initial;
264
-
265
- if (first == null) {
266
- return value;
267
- }
268
-
269
- return asyncPipe(value, ...([first, ...seconds] as GenericCallback[]));
270
- });
271
- }
272
-
273
- // #endregion
274
-
275
- // #region Synchronous
276
-
277
- /**
278
- * Attempt to pipe a value through a function
279
- *
280
- * @param initial Initial value
281
- * @returns _Piped_ result
282
- */
283
- export function attemptPipe<Initial, Pipe>(
284
- initial: GenericCallback | Initial | Result<Initial>,
285
- pipe: (value: UnwrapValue<Initial>) => Pipe,
286
- ): WrapValue<Pipe>;
287
-
288
- /**
289
- * Attempt to pipe a value through a series of functions
290
- *
291
- * @param initial Initial value
292
- * @returns _Piped_ result
293
- */
294
- export function attemptPipe<Initial, First, Second>(
295
- initial: GenericCallback | Initial | Result<Initial>,
296
- first: (value: UnwrapValue<Initial>) => First,
297
- second: (value: UnwrapValue<First>) => Second,
298
- ): WrapValue<Second>;
299
-
300
- /**
301
- * Attempt to pipe a value through a series of functions
302
- *
303
- * @param initial Initial value
304
- * @returns _Piped_ result
305
- */
306
- export function attemptPipe<Initial, First, Second, Third>(
307
- initial: GenericCallback | Initial | Result<Initial>,
308
- first: (value: UnwrapValue<Initial>) => First,
309
- second: (value: UnwrapValue<First>) => Second,
310
- third: (value: UnwrapValue<Second>) => Third,
311
- ): WrapValue<Third>;
312
-
313
- /**
314
- * Attempt to pipe a value through a series of functions
315
- *
316
- * @param initial Initial value
317
- * @returns _Piped_ result
318
- */
319
- export function attemptPipe<Initial, First, Second, Third, Fourth>(
320
- initial: GenericCallback | Initial | Result<Initial>,
321
- first: (value: UnwrapValue<Initial>) => First,
322
- second: (value: UnwrapValue<First>) => Second,
323
- third: (value: UnwrapValue<Second>) => Third,
324
- fourth: (value: UnwrapValue<Third>) => Fourth,
325
- ): WrapValue<Fourth>;
326
-
327
- /**
328
- * Attempt to pipe a value through a series of functions
329
- *
330
- * @param initial Initial value
331
- * @returns _Piped_ result
332
- */
333
- export function attemptPipe<Initial, First, Second, Third, Fourth, Fifth>(
334
- initial: GenericCallback | Initial | Result<Initial>,
335
- first: (value: UnwrapValue<Initial>) => First,
336
- second: (value: UnwrapValue<First>) => Second,
337
- third: (value: UnwrapValue<Second>) => Third,
338
- fourth: (value: UnwrapValue<Third>) => Fourth,
339
- fifth: (value: UnwrapValue<Fourth>) => Fifth,
340
- ): WrapValue<Fifth>;
341
-
342
- /**
343
- * Attempt to pipe a value through a series of functions
344
- *
345
- * @param initial Initial value
346
- * @returns _Piped_ result
347
- */
348
- export function attemptPipe<Initial, First, Second, Third, Fourth, Fifth, Sixth>(
349
- initial: GenericCallback | Initial | Result<Initial>,
350
- first: (value: UnwrapValue<Initial>) => First,
351
- second: (value: UnwrapValue<First>) => Second,
352
- third: (value: UnwrapValue<Second>) => Third,
353
- fourth: (value: UnwrapValue<Third>) => Fourth,
354
- fifth: (value: UnwrapValue<Fourth>) => Fifth,
355
- sixth: (value: UnwrapValue<Fifth>) => Sixth,
356
- ): WrapValue<Sixth>;
357
-
358
- /**
359
- * Attempt to pipe a value through a series of functions
360
- *
361
- * @param initial Initial value
362
- * @returns _Piped_ result
363
- */
364
- export function attemptPipe<Initial, First, Second, Third, Fourth, Fifth, Sixth, Seventh>(
365
- initial: GenericCallback | Initial | Result<Initial>,
366
- first: (value: UnwrapValue<Initial>) => First,
367
- second: (value: UnwrapValue<First>) => Second,
368
- third: (value: UnwrapValue<Second>) => Third,
369
- fourth: (value: UnwrapValue<Third>) => Fourth,
370
- fifth: (value: UnwrapValue<Fourth>) => Fifth,
371
- sixth: (value: UnwrapValue<Fifth>) => Sixth,
372
- seventh: (value: UnwrapValue<Sixth>) => Seventh,
373
- ): WrapValue<Seventh>;
374
-
375
- /**
376
- * Attempt to pipe a value through a series of functions
377
- *
378
- * @param initial Initial value
379
- * @returns _Piped_ result
380
- */
381
- export function attemptPipe<Initial, First, Second, Third, Fourth, Fifth, Sixth, Seventh, Eighth>(
382
- initial: GenericCallback | Initial | Result<Initial>,
383
- first: (value: UnwrapValue<Initial>) => First,
384
- second: (value: UnwrapValue<First>) => Second,
385
- third: (value: UnwrapValue<Second>) => Third,
386
- fourth: (value: UnwrapValue<Third>) => Fourth,
387
- fifth: (value: UnwrapValue<Fourth>) => Fifth,
388
- sixth: (value: UnwrapValue<Fifth>) => Sixth,
389
- seventh: (value: UnwrapValue<Sixth>) => Seventh,
390
- eighth: (value: UnwrapValue<Seventh>) => Eighth,
391
- ): WrapValue<Eighth>;
392
-
393
- /**
394
- * Attempt to pipe a value through a series of functions
395
- *
396
- * @param initial Initial value
397
- * @returns _Piped_ result
398
- */
399
- export function attemptPipe<
400
- Initial,
401
- First,
402
- Second,
403
- Third,
404
- Fourth,
405
- Fifth,
406
- Sixth,
407
- Seventh,
408
- Eighth,
409
- Ninth,
410
- >(
411
- initial: GenericCallback | Initial | Result<Initial>,
412
- first: (value: UnwrapValue<Initial>) => First,
413
- second: (value: UnwrapValue<First>) => Second,
414
- third: (value: UnwrapValue<Second>) => Third,
415
- fourth: (value: UnwrapValue<Third>) => Fourth,
416
- fifth: (value: UnwrapValue<Fourth>) => Fifth,
417
- sixth: (value: UnwrapValue<Fifth>) => Sixth,
418
- seventh: (value: UnwrapValue<Sixth>) => Seventh,
419
- eighth: (value: UnwrapValue<Seventh>) => Eighth,
420
- ninth: (value: UnwrapValue<Eighth>) => Ninth,
421
- ): WrapValue<Ninth>;
422
-
423
- /**
424
- * Attempt to pipe a value through a series of functions
425
- *
426
- * @param initial Initial value
427
- * @returns _Piped_ result
428
- */
429
- export function attemptPipe<
430
- Initial,
431
- First,
432
- Second,
433
- Third,
434
- Fourth,
435
- Fifth,
436
- Sixth,
437
- Seventh,
438
- Eighth,
439
- Ninth,
440
- Tenth,
441
- >(
442
- initial: GenericCallback | Initial | Result<Initial>,
443
- first: (value: UnwrapValue<Initial>) => First,
444
- second: (value: UnwrapValue<First>) => Second,
445
- third: (value: UnwrapValue<Second>) => Third,
446
- fourth: (value: UnwrapValue<Third>) => Fourth,
447
- fifth: (value: UnwrapValue<Fourth>) => Fifth,
448
- sixth: (value: UnwrapValue<Fifth>) => Sixth,
449
- seventh: (value: UnwrapValue<Sixth>) => Seventh,
450
- eighth: (value: UnwrapValue<Seventh>) => Eighth,
451
- ninth: (value: UnwrapValue<Eighth>) => Ninth,
452
- tenth: (value: UnwrapValue<Ninth>) => Tenth,
453
- ): WrapValue<Tenth>;
454
-
455
- /**
456
- * Attempt to pipe a result through a series of functions
457
- *
458
- * @param initial Initial result
459
- * @returns _Piped_ result
460
- */
461
- export function attemptPipe<Initial>(
462
- initial: GenericCallback | Initial | Result<Initial>,
463
- first?: (value: UnwrapValue<Initial>) => unknown,
464
- ...seconds: Array<(value: unknown) => unknown>
465
- ): WrapValue<Initial>;
466
-
467
- export function attemptPipe(
468
- initial: unknown,
469
- first?: (value: unknown) => unknown,
470
- ...seconds: Array<(value: unknown) => unknown>
471
- ): WrapValue<unknown> {
472
- return attempt(() => {
473
- if (isError(initial)) {
474
- throw initial.error;
475
- }
476
-
477
- const value =
478
- typeof initial === 'function'
479
- ? (initial as Function)()
480
- : isOk(initial)
481
- ? initial.value
482
- : initial;
483
-
484
- if (first == null) {
485
- return value;
486
- }
487
-
488
- return pipe(value, ...([first, ...seconds] as GenericCallback[]));
489
- });
490
- }
491
-
492
- attemptPipe.async = attemptAsyncPipe;
493
-
494
- // #endregion
495
-
496
- // #endregion
package/src/sized/map.ts DELETED
@@ -1,110 +0,0 @@
1
- import {getSizedMaximum} from '../internal/sized';
2
-
3
- // #region Types and classes
4
-
5
- /**
6
- * A _Map_ with a maximum size
7
- *
8
- * Behavior is similar to a _LRU_ cache, where the least recently used entries are removed
9
- */
10
- export class SizedMap<SizedKey = unknown, SizedValue = unknown> extends Map<SizedKey, SizedValue> {
11
- /**
12
- * The maximum size of the _Map_
13
- */
14
- readonly #maximumSize: number;
15
-
16
- /**
17
- * Is the _Map_ full?
18
- */
19
- get full(): boolean {
20
- return super.size >= this.#maximumSize;
21
- }
22
-
23
- get maximum(): number {
24
- return this.#maximumSize;
25
- }
26
-
27
- /**
28
- * Create a new _SizedMap_ with entries and a maximum size _(2^20)_
29
- *
30
- * @param entries Array of key-value pairs to initialize the _SizedMap_ with
31
- * @template SizedKey Type of the keys in the _SizedMap_
32
- * @template SizedValue Type of the values in the _SizedMap_
33
- */
34
- constructor(entries: [SizedKey, SizedValue][]);
35
-
36
- /**
37
- * Create a new _SizedMap_ with a maximum size _(but clamped at 2^24)_
38
- *
39
- * @param maximum Maximum size of the _SizedMap_
40
- * @template SizedKey Type of the keys in the _SizedMap_
41
- * @template SizedValue Type of the values in the _SizedMap_
42
- */
43
- constructor(maximum: number);
44
-
45
- /**
46
- * Create a new _SizedMap_ with _(optional)_ entries and a maximum size
47
- *
48
- * @param entries Array of key-value pairs to initialize the _SizedMap_ with
49
- * @param maximum Maximum size of the _SizedMap_ _(defaults to 2^20; clamped at 2^24)_
50
- * @template SizedKey Type of the keys in the _SizedMap_
51
- * @template SizedValue Type of the values in the _SizedMap_
52
- */
53
- constructor(entries?: [SizedKey, SizedValue][], maximum?: number);
54
-
55
- constructor(first?: [SizedKey, SizedValue][] | number, second?: number) {
56
- const maximum = getSizedMaximum(first, second);
57
-
58
- super();
59
-
60
- this.#maximumSize = maximum;
61
-
62
- if (Array.isArray(first)) {
63
- const {length} = first;
64
-
65
- if (length <= maximum) {
66
- for (let index = 0; index < length; index += 1) {
67
- this.set(...first[index]);
68
- }
69
- } else {
70
- for (let index = 0; index < maximum; index += 1) {
71
- this.set(...first[length - maximum + index]);
72
- }
73
- }
74
- }
75
- }
76
-
77
- /**
78
- * @inheritdoc
79
- */
80
- override get(key: SizedKey): SizedValue | undefined {
81
- if (super.has(key)) {
82
- const value = super.get(key) as SizedValue;
83
-
84
- this.#setValue(key, value, true);
85
-
86
- return value;
87
- }
88
- }
89
-
90
- /**
91
- * @inheritdoc
92
- */
93
- override set(key: SizedKey, value: SizedValue): this {
94
- return this.#setValue(key, value, super.has(key));
95
- }
96
-
97
- #setValue(key: SizedKey, value: SizedValue, has: boolean): this {
98
- if (has) {
99
- super.delete(key);
100
- } else if (super.size >= this.#maximumSize) {
101
- super.delete(super.keys().next().value as SizedKey);
102
- }
103
-
104
- super.set(key, value);
105
-
106
- return this;
107
- }
108
- }
109
-
110
- // #endregion
package/src/sized/set.ts DELETED
@@ -1,107 +0,0 @@
1
- import {getSizedMaximum} from '../internal/sized';
2
-
3
- // #region Types
4
-
5
- /**
6
- * A _Set_ with a maximum size
7
- *
8
- * Behavior is similar to a _LRU_ cache, where the oldest values are removed
9
- */
10
- export class SizedSet<Value = unknown> extends Set<Value> {
11
- /**
12
- * The maximum size of the _Set_
13
- */
14
- readonly #maximumSize: number;
15
-
16
- /**
17
- * Is the _Set_ full?
18
- */
19
- get full(): boolean {
20
- return this.size >= this.#maximumSize;
21
- }
22
-
23
- get maximum(): number {
24
- return this.#maximumSize;
25
- }
26
-
27
- /**
28
- * Create a new _SizedSet_ with values and a maximum size _(2^20)_
29
- *
30
- * @param values Array of values to initialize the _SizedSet_ with
31
- * @template Value Type of the values in the _SizedSet_
32
- */
33
- constructor(values: Value[]);
34
-
35
- /**
36
- * Create a new _SizedSet_ with a maximum size _(but clamped at 2^24)_
37
- *
38
- * @param maximum Maximum size of the _SizedSet_ _(defaults to 2^20; clamped at 2^24)_
39
- * @template Value Type of the values in the _SizedSet_
40
- */
41
- constructor(maximum: number);
42
-
43
- /**
44
- * Create a new _SizedSet_ with _(optional)_ values and a maximum size
45
- *
46
- * @param values Array of values to initialize the _SizedSet_ with
47
- * @param maximum Maximum size of the _SizedSet_ _(defaults to 2^20; clamped at 2^24)_
48
- * @template Value Type of the values in the _SizedSet_
49
- */
50
- constructor(values?: Value[], maximum?: number);
51
-
52
- constructor(first?: Value[] | number, second?: number) {
53
- const maximum = getSizedMaximum(first, second);
54
-
55
- super();
56
-
57
- this.#maximumSize = maximum;
58
-
59
- if (Array.isArray(first)) {
60
- const {length} = first;
61
-
62
- if (length <= maximum) {
63
- for (let index = 0; index < length; index += 1) {
64
- this.add(first[index]);
65
- }
66
- } else {
67
- for (let index = 0; index < maximum; index += 1) {
68
- this.add(first[length - maximum + index]);
69
- }
70
- }
71
- }
72
- }
73
-
74
- /**
75
- * @inheritdoc
76
- */
77
- override add(value: Value): this {
78
- if (super.has(value)) {
79
- super.delete(value);
80
- } else if (this.size >= this.#maximumSize) {
81
- super.delete(this.values().next().value as Value);
82
- }
83
-
84
- return super.add(value);
85
- }
86
-
87
- /**
88
- * Get a value from the _SizedSet_, if it exists _(and optionally move it to the end)_
89
- *
90
- * @param value Value to get from the _SizedSet_
91
- * @param update Update the value's position in the _SizedSet_? _(defaults to `false`)_
92
- * @returns Found value if it exists, otherwise `undefined`
93
- */
94
- get(value: Value, update?: boolean): Value | undefined {
95
- if (super.has(value)) {
96
- if (update ?? false) {
97
- super.delete(value);
98
-
99
- this.add(value);
100
- }
101
-
102
- return value;
103
- }
104
- }
105
- }
106
-
107
- // #endregion