@oscarpalmer/atoms 0.193.0 → 0.194.0

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 (204) hide show
  1. package/dist/array/difference.mjs +2 -2
  2. package/dist/array/intersection.mjs +2 -2
  3. package/dist/array/match.mjs +13 -13
  4. package/dist/array/slice.mjs +5 -5
  5. package/dist/array/sort.d.mts +5 -1
  6. package/dist/array/sort.mjs +4 -2
  7. package/dist/array/union.mjs +2 -2
  8. package/dist/beacon.d.mts +8 -1
  9. package/dist/beacon.mjs +52 -60
  10. package/dist/color/constants.d.mts +1 -1
  11. package/dist/color/constants.mjs +3 -5
  12. package/dist/color/instance.mjs +34 -41
  13. package/dist/color/misc/format.d.mts +3 -2
  14. package/dist/color/misc/format.mjs +4 -1
  15. package/dist/color/misc/is.d.mts +9 -1
  16. package/dist/color/misc/is.mjs +11 -1
  17. package/dist/color/misc/state.d.mts +6 -6
  18. package/dist/color/misc/state.mjs +11 -14
  19. package/dist/color/models.d.mts +23 -68
  20. package/dist/function/assert.mjs +2 -2
  21. package/dist/function/limit.d.mts +0 -6
  22. package/dist/function/limit.mjs +2 -2
  23. package/dist/function/memoize.mjs +19 -32
  24. package/dist/function/once.d.mts +0 -3
  25. package/dist/function/once.mjs +16 -13
  26. package/dist/function/retry.d.mts +1 -24
  27. package/dist/function/retry.mjs +1 -1
  28. package/dist/function/work.mjs +13 -11
  29. package/dist/herald.d.mts +30 -31
  30. package/dist/herald.mjs +74 -56
  31. package/dist/index.d.mts +100 -185
  32. package/dist/index.mjs +680 -702
  33. package/dist/internal/abort.d.mts +10 -0
  34. package/dist/internal/abort.mjs +14 -0
  35. package/dist/internal/array/chunk.mjs +2 -2
  36. package/dist/internal/array/find.mjs +2 -2
  37. package/dist/internal/array/sets.d.mts +4 -4
  38. package/dist/internal/array/sets.mjs +7 -7
  39. package/dist/internal/function/timer.mjs +19 -15
  40. package/dist/internal/number.mjs +7 -7
  41. package/dist/internal/result.mjs +3 -3
  42. package/dist/internal/sized.mjs +4 -4
  43. package/dist/internal/string.mjs +4 -4
  44. package/dist/internal/subscription.d.mts +24 -8
  45. package/dist/internal/subscription.mjs +49 -36
  46. package/dist/internal/value/equal.mjs +6 -6
  47. package/dist/internal/value/misc.mjs +14 -14
  48. package/dist/internal/value/set.mjs +2 -2
  49. package/dist/logger.mjs +15 -39
  50. package/dist/promise/constants.d.mts +17 -0
  51. package/dist/promise/constants.mjs +14 -0
  52. package/dist/promise/delay.mjs +7 -10
  53. package/dist/promise/helpers.mjs +1 -1
  54. package/dist/promise/index.mjs +14 -17
  55. package/dist/promise/misc.d.mts +2 -1
  56. package/dist/promise/misc.mjs +8 -7
  57. package/dist/promise/models.d.mts +4 -16
  58. package/dist/promise/models.mjs +4 -13
  59. package/dist/promise/timed.mjs +9 -10
  60. package/dist/query.mjs +15 -15
  61. package/dist/queue.mjs +103 -116
  62. package/dist/random.mjs +7 -7
  63. package/dist/result/index.d.mts +0 -3
  64. package/dist/result/index.mjs +1 -1
  65. package/dist/result/match.d.mts +0 -3
  66. package/dist/result/match.mjs +4 -4
  67. package/dist/result/misc.mjs +2 -2
  68. package/dist/result/work/flow.d.mts +0 -3
  69. package/dist/result/work/flow.mjs +5 -5
  70. package/dist/result/work/pipe.d.mts +0 -3
  71. package/dist/result/work/pipe.mjs +3 -3
  72. package/dist/string/case.mjs +20 -20
  73. package/dist/string/fuzzy.mjs +23 -18
  74. package/dist/string/index.mjs +7 -7
  75. package/dist/string/normalize.mjs +14 -14
  76. package/dist/string/template.mjs +2 -2
  77. package/dist/value/clone.mjs +10 -10
  78. package/dist/value/smush.mjs +2 -2
  79. package/package.json +13 -5
  80. package/src/array/difference.ts +0 -73
  81. package/src/array/exists.ts +0 -93
  82. package/src/array/filter.ts +0 -182
  83. package/src/array/find.ts +0 -183
  84. package/src/array/first.ts +0 -196
  85. package/src/array/flatten.ts +0 -20
  86. package/src/array/from.ts +0 -129
  87. package/src/array/get.ts +0 -131
  88. package/src/array/group-by.ts +0 -369
  89. package/src/array/index.ts +0 -26
  90. package/src/array/insert.ts +0 -52
  91. package/src/array/intersection.ts +0 -72
  92. package/src/array/last.ts +0 -194
  93. package/src/array/match.ts +0 -436
  94. package/src/array/move.ts +0 -315
  95. package/src/array/partition.ts +0 -91
  96. package/src/array/push.ts +0 -23
  97. package/src/array/reverse.ts +0 -33
  98. package/src/array/select.ts +0 -260
  99. package/src/array/single.ts +0 -93
  100. package/src/array/slice.ts +0 -335
  101. package/src/array/sort.ts +0 -607
  102. package/src/array/splice.ts +0 -106
  103. package/src/array/swap.ts +0 -322
  104. package/src/array/to-map.ts +0 -371
  105. package/src/array/to-record.ts +0 -351
  106. package/src/array/to-set.ts +0 -80
  107. package/src/array/toggle.ts +0 -79
  108. package/src/array/union.ts +0 -72
  109. package/src/array/unique.ts +0 -67
  110. package/src/array/update.ts +0 -75
  111. package/src/beacon.ts +0 -378
  112. package/src/color/constants.ts +0 -137
  113. package/src/color/index.ts +0 -83
  114. package/src/color/instance.ts +0 -162
  115. package/src/color/misc/alpha.ts +0 -56
  116. package/src/color/misc/format.ts +0 -29
  117. package/src/color/misc/get.ts +0 -210
  118. package/src/color/misc/is.ts +0 -221
  119. package/src/color/misc/state.ts +0 -243
  120. package/src/color/models.ts +0 -389
  121. package/src/color/space/hex.ts +0 -184
  122. package/src/color/space/hsl.ts +0 -174
  123. package/src/color/space/hwb.ts +0 -153
  124. package/src/color/space/rgb.ts +0 -240
  125. package/src/function/assert.ts +0 -174
  126. package/src/function/index.ts +0 -2
  127. package/src/function/limit.ts +0 -83
  128. package/src/function/memoize.ts +0 -202
  129. package/src/function/once.ts +0 -200
  130. package/src/function/retry.ts +0 -175
  131. package/src/function/work.ts +0 -1007
  132. package/src/herald.ts +0 -216
  133. package/src/index.ts +0 -68
  134. package/src/internal/array/callbacks.ts +0 -46
  135. package/src/internal/array/chunk.ts +0 -51
  136. package/src/internal/array/compact.ts +0 -56
  137. package/src/internal/array/find.ts +0 -200
  138. package/src/internal/array/group.ts +0 -42
  139. package/src/internal/array/index-of.ts +0 -182
  140. package/src/internal/array/insert.ts +0 -80
  141. package/src/internal/array/overlap.ts +0 -35
  142. package/src/internal/array/sets.ts +0 -74
  143. package/src/internal/array/shuffle.ts +0 -33
  144. package/src/internal/array/update.ts +0 -52
  145. package/src/internal/function/misc.ts +0 -8
  146. package/src/internal/function/timer.ts +0 -168
  147. package/src/internal/is.ts +0 -244
  148. package/src/internal/math/aggregate.ts +0 -164
  149. package/src/internal/math/misc.ts +0 -28
  150. package/src/internal/number.ts +0 -129
  151. package/src/internal/random.ts +0 -49
  152. package/src/internal/result.ts +0 -92
  153. package/src/internal/sized.ts +0 -25
  154. package/src/internal/string.ts +0 -128
  155. package/src/internal/subscription.ts +0 -264
  156. package/src/internal/value/compare.ts +0 -170
  157. package/src/internal/value/equal.ts +0 -465
  158. package/src/internal/value/get.ts +0 -57
  159. package/src/internal/value/handlers.ts +0 -95
  160. package/src/internal/value/has.ts +0 -118
  161. package/src/internal/value/misc.ts +0 -125
  162. package/src/internal/value/partial.ts +0 -46
  163. package/src/internal/value/set.ts +0 -132
  164. package/src/is.ts +0 -182
  165. package/src/logger.ts +0 -230
  166. package/src/math.ts +0 -281
  167. package/src/models.ts +0 -286
  168. package/src/number.ts +0 -1
  169. package/src/promise/delay.ts +0 -62
  170. package/src/promise/helpers.ts +0 -96
  171. package/src/promise/index.ts +0 -300
  172. package/src/promise/misc.ts +0 -96
  173. package/src/promise/models.ts +0 -195
  174. package/src/promise/timed.ts +0 -91
  175. package/src/query.ts +0 -147
  176. package/src/queue.ts +0 -814
  177. package/src/random.ts +0 -125
  178. package/src/result/index.ts +0 -105
  179. package/src/result/match.ts +0 -124
  180. package/src/result/misc.ts +0 -129
  181. package/src/result/models.ts +0 -83
  182. package/src/result/work/flow.ts +0 -488
  183. package/src/result/work/pipe.ts +0 -496
  184. package/src/sized/map.ts +0 -110
  185. package/src/sized/set.ts +0 -107
  186. package/src/string/case.ts +0 -236
  187. package/src/string/fuzzy.ts +0 -444
  188. package/src/string/index.ts +0 -199
  189. package/src/string/match.ts +0 -80
  190. package/src/string/normalize.ts +0 -205
  191. package/src/string/template.ts +0 -161
  192. package/src/value/clone.ts +0 -319
  193. package/src/value/collection.ts +0 -63
  194. package/src/value/diff.ts +0 -232
  195. package/src/value/freeze.ts +0 -322
  196. package/src/value/handle.ts +0 -3
  197. package/src/value/index.ts +0 -5
  198. package/src/value/merge.ts +0 -278
  199. package/src/value/omit.ts +0 -20
  200. package/src/value/pick.ts +0 -20
  201. package/src/value/shake.ts +0 -45
  202. package/src/value/smush.ts +0 -89
  203. package/src/value/transform.ts +0 -153
  204. package/src/value/unsmush.ts +0 -84
@@ -1,1007 +0,0 @@
1
- import {isError, isOk} from '../internal/result';
2
- import type {GenericCallback} from '../models';
3
- import type {UnwrapValue} from '../result/models';
4
- import {assert, type Asserter} from './assert';
5
-
6
- // #region Types
7
-
8
- /**
9
- * A synchronous _Flow_, a function that pipe a value through a series of functions
10
- */
11
- export type Flow<Callback extends GenericCallback, Value> = (
12
- ...args: Parameters<Callback>
13
- ) => UnwrapValue<Value>;
14
-
15
- /**
16
- * An asynchronous _Flow_, a function that pipes a value through a series of functions
17
- */
18
- export type FlowPromise<Callback extends GenericCallback, Value> = (
19
- ...args: Parameters<Callback>
20
- ) => Promise<UnwrapValue<Value>>;
21
-
22
- // #endregion
23
-
24
- // #region Functions
25
-
26
- // #region Flow
27
-
28
- // #region Asynchronous
29
-
30
- /**
31
- * Create an asynchronous _Flow_, a function that pipes values through a function
32
- *
33
- * _Available as `asyncFlow` and `flow.async`_
34
- *
35
- * @returns _Flow_ function
36
- */
37
- export function asyncFlow<Fn extends GenericCallback>(fn: Fn): FlowPromise<Fn, ReturnType<Fn>>;
38
-
39
- /**
40
- * Create an asynchronous _Flow_, a function that pipes values through a series of functions
41
- *
42
- * _Available as `asyncFlow` and `flow.async`_
43
- *
44
- * @returns _Flow_ function
45
- */
46
- export function asyncFlow<First extends GenericCallback, Second>(
47
- first: First,
48
- second: (value: Awaited<UnwrapValue<ReturnType<First>>>) => Second,
49
- ): FlowPromise<First, Second>;
50
-
51
- /**
52
- * Create an asynchronous _Flow_, a function that pipes values through a series of functions
53
- *
54
- * _Available as `asyncFlow` and `flow.async`_
55
- *
56
- * @returns _Flow_ function
57
- */
58
- export function asyncFlow<First extends GenericCallback, Second, Third>(
59
- first: First,
60
- second: (value: Awaited<UnwrapValue<ReturnType<First>>>) => Second,
61
- third: (value: Awaited<UnwrapValue<Second>>) => Third,
62
- ): FlowPromise<First, Third>;
63
-
64
- /**
65
- * Create an asynchronous _Flow_, a function that pipes values through a series of functions
66
- *
67
- * _Available as `asyncFlow` and `flow.async`_
68
- *
69
- * @returns _Flow_ function
70
- */
71
- export function asyncFlow<First extends GenericCallback, Second, Third, Fourth>(
72
- first: First,
73
- second: (value: Awaited<UnwrapValue<ReturnType<First>>>) => Second,
74
- third: (value: Awaited<UnwrapValue<Second>>) => Third,
75
- fourth: (value: Awaited<UnwrapValue<Third>>) => Fourth,
76
- ): FlowPromise<First, Fourth>;
77
-
78
- /**
79
- * Create an asynchronous _Flow_, a function that pipes values through a series of functions
80
- *
81
- * _Available as `asyncFlow` and `flow.async`_
82
- *
83
- * @returns _Flow_ function
84
- */
85
- export function asyncFlow<First extends GenericCallback, Second, Third, Fourth, Fifth>(
86
- first: First,
87
- second: (value: Awaited<UnwrapValue<ReturnType<First>>>) => Second,
88
- third: (value: Awaited<UnwrapValue<Second>>) => Third,
89
- fourth: (value: Awaited<UnwrapValue<Third>>) => Fourth,
90
- fifth: (value: Awaited<UnwrapValue<Fourth>>) => Fifth,
91
- ): FlowPromise<First, Fifth>;
92
-
93
- /**
94
- * Create an asynchronous _Flow_, a function that pipes values through a series of functions
95
- *
96
- * _Available as `asyncFlow` and `flow.async`_
97
- *
98
- * @returns _Flow_ function
99
- */
100
- export function asyncFlow<First extends GenericCallback, Second, Third, Fourth, Fifth, Sixth>(
101
- first: First,
102
- second: (value: Awaited<UnwrapValue<ReturnType<First>>>) => Second,
103
- third: (value: Awaited<UnwrapValue<Second>>) => Third,
104
- fourth: (value: Awaited<UnwrapValue<Third>>) => Fourth,
105
- fifth: (value: Awaited<UnwrapValue<Fourth>>) => Fifth,
106
- sixth: (value: Awaited<UnwrapValue<Fifth>>) => Sixth,
107
- ): FlowPromise<First, Sixth>;
108
-
109
- /**
110
- * Create an asynchronous _Flow_, a function that pipes values through a series of functions
111
- *
112
- * _Available as `asyncFlow` and `flow.async`_
113
- *
114
- * @returns _Flow_ function
115
- */
116
- export function asyncFlow<
117
- First extends GenericCallback,
118
- Second,
119
- Third,
120
- Fourth,
121
- Fifth,
122
- Sixth,
123
- Seventh,
124
- >(
125
- first: First,
126
- second: (value: Awaited<UnwrapValue<ReturnType<First>>>) => Second,
127
- third: (value: Awaited<UnwrapValue<Second>>) => Third,
128
- fourth: (value: Awaited<UnwrapValue<Third>>) => Fourth,
129
- fifth: (value: Awaited<UnwrapValue<Fourth>>) => Fifth,
130
- sixth: (value: Awaited<UnwrapValue<Fifth>>) => Sixth,
131
- seventh: (value: Awaited<UnwrapValue<Sixth>>) => Seventh,
132
- ): FlowPromise<First, Seventh>;
133
-
134
- /**
135
- * Create an asynchronous _Flow_, a function that pipes values through a series of functions
136
- *
137
- * _Available as `asyncFlow` and `flow.async`_
138
- *
139
- * @returns _Flow_ function
140
- */
141
- export function asyncFlow<
142
- First extends GenericCallback,
143
- Second,
144
- Third,
145
- Fourth,
146
- Fifth,
147
- Sixth,
148
- Seventh,
149
- Eighth,
150
- >(
151
- first: First,
152
- second: (value: Awaited<UnwrapValue<ReturnType<First>>>) => Second,
153
- third: (value: Awaited<UnwrapValue<Second>>) => Third,
154
- fourth: (value: Awaited<UnwrapValue<Third>>) => Fourth,
155
- fifth: (value: Awaited<UnwrapValue<Fourth>>) => Fifth,
156
- sixth: (value: Awaited<UnwrapValue<Fifth>>) => Sixth,
157
- seventh: (value: Awaited<UnwrapValue<Sixth>>) => Seventh,
158
- eighth: (value: Awaited<UnwrapValue<Seventh>>) => Eighth,
159
- ): FlowPromise<First, Eighth>;
160
-
161
- /**
162
- * Create an asynchronous _Flow_, a function that pipes values through a series of functions
163
- *
164
- * _Available as `asyncFlow` and `flow.async`_
165
- *
166
- * @returns _Flow_ function
167
- */
168
- export function asyncFlow<
169
- First extends GenericCallback,
170
- Second,
171
- Third,
172
- Fourth,
173
- Fifth,
174
- Sixth,
175
- Seventh,
176
- Eighth,
177
- Ninth,
178
- >(
179
- first: First,
180
- second: (value: Awaited<UnwrapValue<ReturnType<First>>>) => Second,
181
- third: (value: Awaited<UnwrapValue<Second>>) => Third,
182
- fourth: (value: Awaited<UnwrapValue<Third>>) => Fourth,
183
- fifth: (value: Awaited<UnwrapValue<Fourth>>) => Fifth,
184
- sixth: (value: Awaited<UnwrapValue<Fifth>>) => Sixth,
185
- seventh: (value: Awaited<UnwrapValue<Sixth>>) => Seventh,
186
- eighth: (value: Awaited<UnwrapValue<Seventh>>) => Eighth,
187
- ninth: (value: Awaited<UnwrapValue<Eighth>>) => Ninth,
188
- ): FlowPromise<First, Ninth>;
189
-
190
- /**
191
- * Create an asynchronous _Flow_, a function that pipes values through a series of functions
192
- *
193
- * _Available as `asyncFlow` and `flow.async`_
194
- *
195
- * @returns _Flow_ function
196
- */
197
- export function asyncFlow<
198
- First extends GenericCallback,
199
- Second,
200
- Third,
201
- Fourth,
202
- Fifth,
203
- Sixth,
204
- Seventh,
205
- Eighth,
206
- Ninth,
207
- Tenth,
208
- >(
209
- first: First,
210
- second: (value: Awaited<UnwrapValue<ReturnType<First>>>) => Second,
211
- third: (value: Awaited<UnwrapValue<Second>>) => Third,
212
- fourth: (value: Awaited<UnwrapValue<Third>>) => Fourth,
213
- fifth: (value: Awaited<UnwrapValue<Fourth>>) => Fifth,
214
- sixth: (value: Awaited<UnwrapValue<Fifth>>) => Sixth,
215
- seventh: (value: Awaited<UnwrapValue<Sixth>>) => Seventh,
216
- eighth: (value: Awaited<UnwrapValue<Seventh>>) => Eighth,
217
- ninth: (value: Awaited<UnwrapValue<Eighth>>) => Ninth,
218
- tenth: (value: Awaited<UnwrapValue<Ninth>>) => Tenth,
219
- ): FlowPromise<First, Tenth>;
220
-
221
- /**
222
- * Create an asynchronous _Flow_, a function that pipes values through a series of functions
223
- *
224
- * _Available as `asyncFlow` and `flow.async`_
225
- *
226
- * @returns _Flow_ function
227
- */
228
- export function asyncFlow<Fn extends GenericCallback>(
229
- fn: Fn,
230
- ...fns: Array<(value: Awaited<UnwrapValue<ReturnType<Fn>>>) => unknown>
231
- ): FlowPromise<Fn, ReturnType<Fn>>;
232
-
233
- /**
234
- * Create an asynchronous _Flow_, a function that pipes values through a series of functions
235
- *
236
- * _Available as `asyncFlow` and `flow.async`_
237
- *
238
- * @returns _Flow_ function
239
- */
240
- export function asyncFlow(...fns: GenericCallback[]): (...args: unknown[]) => Promise<unknown>;
241
-
242
- export function asyncFlow(...fns: GenericCallback[]): (...args: unknown[]) => Promise<unknown> {
243
- assertFlowFunctions(fns);
244
-
245
- return (...args: unknown[]): Promise<unknown> =>
246
- asyncWork(
247
- args.map(value => {
248
- if (isError(value)) {
249
- throw value.error;
250
- }
251
-
252
- return isOk(value) ? value.value : value;
253
- }),
254
- fns,
255
- true,
256
- );
257
- }
258
-
259
- // #endregion
260
-
261
- // #region Synchronous
262
-
263
- /**
264
- * Create a _Flow_, a function that pipes values through a function
265
- *
266
- * @returns _Flow_ function
267
- */
268
- export function flow<Fn extends GenericCallback>(fn: Fn): Flow<Fn, ReturnType<Fn>>;
269
-
270
- /**
271
- * Create a _Flow_, a function that pipes values through a series of functions
272
- *
273
- * @returns _Flow_ function
274
- */
275
- export function flow<First extends GenericCallback, Second>(
276
- first: First,
277
- second: (value: UnwrapValue<ReturnType<First>>) => Second,
278
- ): Flow<First, Second>;
279
-
280
- /**
281
- * Create a _Flow_, a function that pipes values through a series of functions
282
- *
283
- * @returns _Flow_ function
284
- */
285
- export function flow<First extends GenericCallback, Second, Third>(
286
- first: First,
287
- second: (value: UnwrapValue<ReturnType<First>>) => Second,
288
- third: (value: UnwrapValue<Second>) => Third,
289
- ): Flow<First, Third>;
290
-
291
- /**
292
- * Create a _Flow_, a function that pipes values through a series of functions
293
- *
294
- * @returns _Flow_ function
295
- */
296
- export function flow<First extends GenericCallback, Second, Third, Fourth>(
297
- first: First,
298
- second: (value: UnwrapValue<ReturnType<First>>) => Second,
299
- third: (value: UnwrapValue<Second>) => Third,
300
- fourth: (value: UnwrapValue<Third>) => Fourth,
301
- ): Flow<First, Fourth>;
302
-
303
- /**
304
- * Create a _Flow_, a function that pipes values through a series of functions
305
- *
306
- * @returns _Flow_ function
307
- */
308
- export function flow<First extends GenericCallback, Second, Third, Fourth, Fifth>(
309
- first: First,
310
- second: (value: UnwrapValue<ReturnType<First>>) => Second,
311
- third: (value: UnwrapValue<Second>) => Third,
312
- fourth: (value: UnwrapValue<Third>) => Fourth,
313
- fifth: (value: UnwrapValue<Fourth>) => Fifth,
314
- ): Flow<First, Fifth>;
315
-
316
- /**
317
- * Create a _Flow_, a function that pipes values through a series of functions
318
- *
319
- * @returns _Flow_ function
320
- */
321
- export function flow<First extends GenericCallback, Second, Third, Fourth, Fifth, Sixth>(
322
- first: First,
323
- second: (value: UnwrapValue<ReturnType<First>>) => Second,
324
- third: (value: UnwrapValue<Second>) => Third,
325
- fourth: (value: UnwrapValue<Third>) => Fourth,
326
- fifth: (value: UnwrapValue<Fourth>) => Fifth,
327
- sixth: (value: UnwrapValue<Fifth>) => Sixth,
328
- ): Flow<First, Sixth>;
329
-
330
- /**
331
- * Create a _Flow_, a function that pipes values through a series of functions
332
- *
333
- * @returns _Flow_ function
334
- */
335
- export function flow<First extends GenericCallback, Second, Third, Fourth, Fifth, Sixth, Seventh>(
336
- first: First,
337
- second: (value: UnwrapValue<ReturnType<First>>) => Second,
338
- third: (value: UnwrapValue<Second>) => Third,
339
- fourth: (value: UnwrapValue<Third>) => Fourth,
340
- fifth: (value: UnwrapValue<Fourth>) => Fifth,
341
- sixth: (value: UnwrapValue<Fifth>) => Sixth,
342
- seventh: (value: UnwrapValue<Sixth>) => Seventh,
343
- ): Flow<First, Seventh>;
344
-
345
- /**
346
- * Create a _Flow_, a function that pipes values through a series of functions
347
- *
348
- * @returns _Flow_ function
349
- */
350
- export function flow<
351
- First extends GenericCallback,
352
- Second,
353
- Third,
354
- Fourth,
355
- Fifth,
356
- Sixth,
357
- Seventh,
358
- Eighth,
359
- >(
360
- first: First,
361
- second: (value: UnwrapValue<ReturnType<First>>) => Second,
362
- third: (value: UnwrapValue<Second>) => Third,
363
- fourth: (value: UnwrapValue<Third>) => Fourth,
364
- fifth: (value: UnwrapValue<Fourth>) => Fifth,
365
- sixth: (value: UnwrapValue<Fifth>) => Sixth,
366
- seventh: (value: UnwrapValue<Sixth>) => Seventh,
367
- eighth: (value: UnwrapValue<Seventh>) => Eighth,
368
- ): Flow<First, Eighth>;
369
-
370
- /**
371
- * Create a _Flow_, a function that pipes values through a series of functions
372
- *
373
- * @returns _Flow_ function
374
- */
375
- export function flow<
376
- First extends GenericCallback,
377
- Second,
378
- Third,
379
- Fourth,
380
- Fifth,
381
- Sixth,
382
- Seventh,
383
- Eighth,
384
- Ninth,
385
- >(
386
- first: First,
387
- second: (value: UnwrapValue<ReturnType<First>>) => Second,
388
- third: (value: UnwrapValue<Second>) => Third,
389
- fourth: (value: UnwrapValue<Third>) => Fourth,
390
- fifth: (value: UnwrapValue<Fourth>) => Fifth,
391
- sixth: (value: UnwrapValue<Fifth>) => Sixth,
392
- seventh: (value: UnwrapValue<Sixth>) => Seventh,
393
- eighth: (value: UnwrapValue<Seventh>) => Eighth,
394
- ninth: (value: UnwrapValue<Eighth>) => Ninth,
395
- ): Flow<First, Ninth>;
396
-
397
- /**
398
- * Create a _Flow_, a function that pipes values through a series of functions
399
- *
400
- * @returns _Flow_ function
401
- */
402
- export function flow<
403
- First extends GenericCallback,
404
- Second,
405
- Third,
406
- Fourth,
407
- Fifth,
408
- Sixth,
409
- Seventh,
410
- Eighth,
411
- Ninth,
412
- Tenth,
413
- >(
414
- first: First,
415
- second: (value: UnwrapValue<ReturnType<First>>) => Second,
416
- third: (value: UnwrapValue<Second>) => Third,
417
- fourth: (value: UnwrapValue<Third>) => Fourth,
418
- fifth: (value: UnwrapValue<Fourth>) => Fifth,
419
- sixth: (value: UnwrapValue<Fifth>) => Sixth,
420
- seventh: (value: UnwrapValue<Sixth>) => Seventh,
421
- eighth: (value: UnwrapValue<Seventh>) => Eighth,
422
- ninth: (value: UnwrapValue<Eighth>) => Ninth,
423
- tenth: (value: UnwrapValue<Ninth>) => Tenth,
424
- ): Flow<First, Tenth>;
425
-
426
- /**
427
- * Create a _Flow_, a function that pipes values through a series of functions
428
- *
429
- * @returns _Flow_ function
430
- */
431
- export function flow<First extends GenericCallback>(
432
- first: First,
433
- ...fns: Array<(value: UnwrapValue<ReturnType<First>>) => unknown>
434
- ): Flow<First, ReturnType<First>>;
435
-
436
- /**
437
- * Create a _Flow_, a function that pipes values through a series of functions
438
- *
439
- * @returns _Flow_ function
440
- */
441
- export function flow(...fns: GenericCallback[]): (...args: unknown[]) => unknown;
442
-
443
- export function flow(...fns: GenericCallback[]): (...args: unknown[]) => unknown {
444
- assertFlowFunctions(fns);
445
-
446
- return (...args: unknown[]): unknown =>
447
- work(
448
- args.map(value => {
449
- if (isError(value)) {
450
- throw value.error;
451
- }
452
-
453
- return isOk(value) ? value.value : value;
454
- }),
455
- fns,
456
- true,
457
- );
458
- }
459
-
460
- flow.async = asyncFlow;
461
-
462
- // #endregion
463
-
464
- // #endregion
465
-
466
- // #region Pipe
467
-
468
- // #region Asynchronous
469
-
470
- /**
471
- * Pipe a value through a function
472
- *
473
- * _Available as `asyncPipe` and `pipe.async`_
474
- *
475
- * @param value Initial value
476
- * @returns _Piped_ result
477
- */
478
- export async function asyncPipe<Initial, Piped>(
479
- value: Initial,
480
- pipe: (value: UnwrapValue<Initial>) => Piped,
481
- ): Promise<UnwrapValue<Piped>>;
482
-
483
- /**
484
- * Pipe a value through a series of functions
485
- *
486
- * _Available as `asyncPipe` and `pipe.async`_
487
- *
488
- * @param value Initial value
489
- * @returns _Piped_ result
490
- */
491
- export async function asyncPipe<Initial, First, Second>(
492
- value: Initial,
493
- first: (value: UnwrapValue<Initial>) => First,
494
- second: (value: UnwrapValue<First>) => Second,
495
- ): Promise<UnwrapValue<Second>>;
496
-
497
- /**
498
- * Pipe a value through a series of functions
499
- *
500
- * _Available as `asyncPipe` and `pipe.async`_
501
- *
502
- * @param value Initial value
503
- * @returns _Piped_ result
504
- */
505
- export async function asyncPipe<Initial, First, Second, Third>(
506
- value: Initial,
507
- first: (value: UnwrapValue<Initial>) => First,
508
- second: (value: UnwrapValue<First>) => Second,
509
- third: (value: UnwrapValue<Second>) => Third,
510
- ): Promise<UnwrapValue<Third>>;
511
-
512
- /**
513
- * Pipe a value through a series of functions
514
- *
515
- * _Available as `asyncPipe` and `pipe.async`_
516
- *
517
- * @param value Initial value
518
- * @returns _Piped_ result
519
- */
520
- export async function asyncPipe<Initial, First, Second, Third, Fourth>(
521
- value: Initial,
522
- first: (value: UnwrapValue<Initial>) => First,
523
- second: (value: UnwrapValue<First>) => Second,
524
- third: (value: UnwrapValue<Second>) => Third,
525
- fourth: (value: UnwrapValue<Third>) => Fourth,
526
- ): Promise<UnwrapValue<Fourth>>;
527
-
528
- /**
529
- * Pipe a value through a series of functions
530
- *
531
- * _Available as `asyncPipe` and `pipe.async`_
532
- *
533
- * @param value Initial value
534
- * @returns _Piped_ result
535
- */
536
- export async function asyncPipe<Initial, First, Second, Third, Fourth, Fifth>(
537
- value: Initial,
538
- first: (value: UnwrapValue<Initial>) => First,
539
- second: (value: UnwrapValue<First>) => Second,
540
- third: (value: UnwrapValue<Second>) => Third,
541
- fourth: (value: UnwrapValue<Third>) => Fourth,
542
- fifth: (value: UnwrapValue<Fourth>) => Fifth,
543
- ): Promise<UnwrapValue<Fifth>>;
544
-
545
- /**
546
- * Pipe a value through a series of functions
547
- *
548
- * _Available as `asyncPipe` and `pipe.async`_
549
- *
550
- * @param value Initial value
551
- * @returns _Piped_ result
552
- */
553
- export async function asyncPipe<Initial, First, Second, Third, Fourth, Fifth, Sixth>(
554
- value: Initial,
555
- first: (value: UnwrapValue<Initial>) => First,
556
- second: (value: UnwrapValue<First>) => Second,
557
- third: (value: UnwrapValue<Second>) => Third,
558
- fourth: (value: UnwrapValue<Third>) => Fourth,
559
- fifth: (value: UnwrapValue<Fourth>) => Fifth,
560
- sixth: (value: UnwrapValue<Fifth>) => Sixth,
561
- ): Promise<UnwrapValue<Sixth>>;
562
-
563
- /**
564
- * Pipe a value through a series of functions
565
- *
566
- * _Available as `asyncPipe` and `pipe.async`_
567
- *
568
- * @param value Initial value
569
- * @returns _Piped_ result
570
- */
571
- export async function asyncPipe<Initial, First, Second, Third, Fourth, Fifth, Sixth, Seventh>(
572
- value: Initial,
573
- first: (value: UnwrapValue<Initial>) => First,
574
- second: (value: UnwrapValue<First>) => Second,
575
- third: (value: UnwrapValue<Second>) => Third,
576
- fourth: (value: UnwrapValue<Third>) => Fourth,
577
- fifth: (value: UnwrapValue<Fourth>) => Fifth,
578
- sixth: (value: UnwrapValue<Fifth>) => Sixth,
579
- seventh: (value: UnwrapValue<Sixth>) => Seventh,
580
- ): Promise<UnwrapValue<Seventh>>;
581
-
582
- /**
583
- * Pipe a value through a series of functions
584
- *
585
- * _Available as `asyncPipe` and `pipe.async`_
586
- *
587
- * @param value Initial value
588
- * @returns _Piped_ result
589
- */
590
- export async function asyncPipe<
591
- Initial,
592
- First,
593
- Second,
594
- Third,
595
- Fourth,
596
- Fifth,
597
- Sixth,
598
- Seventh,
599
- Eighth,
600
- >(
601
- value: Initial,
602
- first: (value: UnwrapValue<Initial>) => First,
603
- second: (value: UnwrapValue<First>) => Second,
604
- third: (value: UnwrapValue<Second>) => Third,
605
- fourth: (value: UnwrapValue<Third>) => Fourth,
606
- fifth: (value: UnwrapValue<Fourth>) => Fifth,
607
- sixth: (value: UnwrapValue<Fifth>) => Sixth,
608
- seventh: (value: UnwrapValue<Sixth>) => Seventh,
609
- eighth: (value: UnwrapValue<Seventh>) => Eighth,
610
- ): Promise<UnwrapValue<Eighth>>;
611
-
612
- /**
613
- * Pipe a value through a series of functions
614
- *
615
- * _Available as `asyncPipe` and `pipe.async`_
616
- *
617
- * @param value Initial value
618
- * @returns _Piped_ result
619
- */
620
- export async function asyncPipe<
621
- Initial,
622
- First,
623
- Second,
624
- Third,
625
- Fourth,
626
- Fifth,
627
- Sixth,
628
- Seventh,
629
- Eighth,
630
- Ninth,
631
- >(
632
- value: Initial,
633
- first: (value: UnwrapValue<Initial>) => First,
634
- second: (value: UnwrapValue<First>) => Second,
635
- third: (value: UnwrapValue<Second>) => Third,
636
- fourth: (value: UnwrapValue<Third>) => Fourth,
637
- fifth: (value: UnwrapValue<Fourth>) => Fifth,
638
- sixth: (value: UnwrapValue<Fifth>) => Sixth,
639
- seventh: (value: UnwrapValue<Sixth>) => Seventh,
640
- eighth: (value: UnwrapValue<Seventh>) => Eighth,
641
- ninth: (value: UnwrapValue<Eighth>) => Ninth,
642
- ): Promise<UnwrapValue<Ninth>>;
643
-
644
- /**
645
- * Pipe a value through a series of functions
646
- *
647
- * _Available as `asyncPipe` and `pipe.async`_
648
- *
649
- * @param value Initial value
650
- * @returns _Piped_ result
651
- */
652
- export async function asyncPipe<
653
- Initial,
654
- First,
655
- Second,
656
- Third,
657
- Fourth,
658
- Fifth,
659
- Sixth,
660
- Seventh,
661
- Eighth,
662
- Ninth,
663
- Tenth,
664
- >(
665
- value: Initial,
666
- first: (value: UnwrapValue<Initial>) => First,
667
- second: (value: UnwrapValue<First>) => Second,
668
- third: (value: UnwrapValue<Second>) => Third,
669
- fourth: (value: UnwrapValue<Third>) => Fourth,
670
- fifth: (value: UnwrapValue<Fourth>) => Fifth,
671
- sixth: (value: UnwrapValue<Fifth>) => Sixth,
672
- seventh: (value: UnwrapValue<Sixth>) => Seventh,
673
- eighth: (value: UnwrapValue<Seventh>) => Eighth,
674
- ninth: (value: UnwrapValue<Eighth>) => Ninth,
675
- tenth: (value: UnwrapValue<Ninth>) => Tenth,
676
- ): Promise<UnwrapValue<Tenth>>;
677
-
678
- /**
679
- * Pipe a value through a series of functions
680
- *
681
- * _Available as `asyncPipe` and `pipe.async`_
682
- *
683
- * @param value Initial value
684
- * @returns _Piped_ result
685
- */
686
- export async function asyncPipe<Value>(
687
- value: Value,
688
- ...pipes: Array<(value: Value) => Value>
689
- ): Promise<UnwrapValue<Value>>;
690
-
691
- /**
692
- * Pipe a value through a series of functions
693
- *
694
- * _Available as `asyncPipe` and `pipe.async`_
695
- *
696
- * @param value Initial value
697
- * @returns _Piped_ result
698
- */
699
- export async function asyncPipe(
700
- value: unknown,
701
- ...pipes: Array<(value: unknown) => unknown>
702
- ): Promise<unknown>;
703
-
704
- export async function asyncPipe(
705
- value: unknown,
706
- ...pipes: Array<(value: unknown) => unknown>
707
- ): Promise<unknown> {
708
- assertPipeFunctions(pipes);
709
-
710
- return asyncWork(value, pipes, false);
711
- }
712
-
713
- // #endregion
714
-
715
- // #region Synchronous
716
-
717
- /**
718
- * Pipe a value through a function
719
- *
720
- * @param value Initial value
721
- * @returns _Piped_ result
722
- */
723
- export function pipe<Initial, Piped>(
724
- value: Initial,
725
- pipe: (value: UnwrapValue<Initial>) => Piped,
726
- ): UnwrapValue<Piped>;
727
-
728
- /**
729
- * Pipe a value through a series of functions
730
- *
731
- * @param value Initial value
732
- * @returns _Piped_ result
733
- */
734
- export function pipe<Initial, First, Second>(
735
- value: Initial,
736
- first: (value: UnwrapValue<Initial>) => First,
737
- second: (value: UnwrapValue<First>) => Second,
738
- ): UnwrapValue<Second>;
739
-
740
- /**
741
- * Pipe a value through a series of functions
742
- *
743
- * @param value Initial value
744
- * @returns _Piped_ result
745
- */
746
- export function pipe<Initial, First, Second, Third>(
747
- value: Initial,
748
- first: (value: UnwrapValue<Initial>) => First,
749
- second: (value: UnwrapValue<First>) => Second,
750
- third: (value: UnwrapValue<Second>) => Third,
751
- ): UnwrapValue<Third>;
752
-
753
- /**
754
- * Pipe a value through a series of functions
755
- *
756
- * @param value Initial value
757
- * @returns _Piped_ result
758
- */
759
- export function pipe<Initial, First, Second, Third, Fourth>(
760
- value: Initial,
761
- first: (value: UnwrapValue<Initial>) => First,
762
- second: (value: UnwrapValue<First>) => Second,
763
- third: (value: UnwrapValue<Second>) => Third,
764
- fourth: (value: UnwrapValue<Third>) => Fourth,
765
- ): UnwrapValue<Fourth>;
766
-
767
- /**
768
- * Pipe a value through a series of functions
769
- *
770
- * @param value Initial value
771
- * @returns _Piped_ result
772
- */
773
- export function pipe<Initial, First, Second, Third, Fourth, Fifth>(
774
- value: Initial,
775
- first: (value: UnwrapValue<Initial>) => First,
776
- second: (value: UnwrapValue<First>) => Second,
777
- third: (value: UnwrapValue<Second>) => Third,
778
- fourth: (value: UnwrapValue<Third>) => Fourth,
779
- fifth: (value: UnwrapValue<Fourth>) => Fifth,
780
- ): UnwrapValue<Fifth>;
781
-
782
- /**
783
- * Pipe a value through a series of functions
784
- *
785
- * @param value Initial value
786
- * @returns _Piped_ result
787
- */
788
- export function pipe<Initial, First, Second, Third, Fourth, Fifth, Sixth>(
789
- value: Initial,
790
- first: (value: UnwrapValue<Initial>) => First,
791
- second: (value: UnwrapValue<First>) => Second,
792
- third: (value: UnwrapValue<Second>) => Third,
793
- fourth: (value: UnwrapValue<Third>) => Fourth,
794
- fifth: (value: UnwrapValue<Fourth>) => Fifth,
795
- sixth: (value: UnwrapValue<Fifth>) => Sixth,
796
- ): UnwrapValue<Sixth>;
797
-
798
- /**
799
- * Pipe a value through a series of functions
800
- *
801
- * @param value Initial value
802
- * @returns _Piped_ result
803
- */
804
- export function pipe<Initial, First, Second, Third, Fourth, Fifth, Sixth, Seventh>(
805
- value: Initial,
806
- first: (value: UnwrapValue<Initial>) => First,
807
- second: (value: UnwrapValue<First>) => Second,
808
- third: (value: UnwrapValue<Second>) => Third,
809
- fourth: (value: UnwrapValue<Third>) => Fourth,
810
- fifth: (value: UnwrapValue<Fourth>) => Fifth,
811
- sixth: (value: UnwrapValue<Fifth>) => Sixth,
812
- seventh: (value: UnwrapValue<Sixth>) => Seventh,
813
- ): UnwrapValue<Seventh>;
814
-
815
- /**
816
- * Pipe a value through a series of functions
817
- *
818
- * @param value Initial value
819
- * @returns _Piped_ result
820
- */
821
- export function pipe<Initial, First, Second, Third, Fourth, Fifth, Sixth, Seventh, Eighth>(
822
- value: Initial,
823
- first: (value: UnwrapValue<Initial>) => First,
824
- second: (value: UnwrapValue<First>) => Second,
825
- third: (value: UnwrapValue<Second>) => Third,
826
- fourth: (value: UnwrapValue<Third>) => Fourth,
827
- fifth: (value: UnwrapValue<Fourth>) => Fifth,
828
- sixth: (value: UnwrapValue<Fifth>) => Sixth,
829
- seventh: (value: UnwrapValue<Sixth>) => Seventh,
830
- eighth: (value: UnwrapValue<Seventh>) => Eighth,
831
- ): UnwrapValue<Eighth>;
832
-
833
- /**
834
- * Pipe a value through a series of functions
835
- *
836
- * @param value Initial value
837
- * @returns _Piped_ result
838
- */
839
- export function pipe<Initial, First, Second, Third, Fourth, Fifth, Sixth, Seventh, Eighth, Ninth>(
840
- value: Initial,
841
- first: (value: UnwrapValue<Initial>) => First,
842
- second: (value: UnwrapValue<First>) => Second,
843
- third: (value: UnwrapValue<Second>) => Third,
844
- fourth: (value: UnwrapValue<Third>) => Fourth,
845
- fifth: (value: UnwrapValue<Fourth>) => Fifth,
846
- sixth: (value: UnwrapValue<Fifth>) => Sixth,
847
- seventh: (value: UnwrapValue<Sixth>) => Seventh,
848
- eighth: (value: UnwrapValue<Seventh>) => Eighth,
849
- ninth: (value: UnwrapValue<Eighth>) => Ninth,
850
- ): UnwrapValue<Ninth>;
851
-
852
- /**
853
- * Pipe a value through a series of functions
854
- *
855
- * @param value Initial value
856
- * @returns _Piped_ result
857
- */
858
- export function pipe<
859
- Initial,
860
- First,
861
- Second,
862
- Third,
863
- Fourth,
864
- Fifth,
865
- Sixth,
866
- Seventh,
867
- Eighth,
868
- Ninth,
869
- Tenth,
870
- >(
871
- value: Initial,
872
- first: (value: UnwrapValue<Initial>) => First,
873
- second: (value: UnwrapValue<First>) => Second,
874
- third: (value: UnwrapValue<Second>) => Third,
875
- fourth: (value: UnwrapValue<Third>) => Fourth,
876
- fifth: (value: UnwrapValue<Fourth>) => Fifth,
877
- sixth: (value: UnwrapValue<Fifth>) => Sixth,
878
- seventh: (value: UnwrapValue<Sixth>) => Seventh,
879
- eighth: (value: UnwrapValue<Seventh>) => Eighth,
880
- ninth: (value: UnwrapValue<Eighth>) => Ninth,
881
- tenth: (value: UnwrapValue<Ninth>) => Tenth,
882
- ): UnwrapValue<Tenth>;
883
-
884
- /**
885
- * Pipe a value through a series of functions
886
- *
887
- * @param value Initial value
888
- * @returns _Piped_ result
889
- */
890
- export function pipe<Value>(
891
- value: Value,
892
- ...pipes: Array<(value: Value) => Value>
893
- ): UnwrapValue<Value>;
894
-
895
- /**
896
- * Pipe a value through a series of functions
897
- *
898
- * @param value Initial value
899
- * @returns _Piped_ result
900
- */
901
- export function pipe(value: unknown, ...pipes: Array<(value: unknown) => unknown>): unknown;
902
-
903
- export function pipe(value: unknown, ...pipes: GenericCallback[]): unknown {
904
- assertPipeFunctions(pipes);
905
-
906
- return work(value, pipes, false);
907
- }
908
-
909
- pipe.async = asyncPipe;
910
-
911
- // #endregion
912
-
913
- // #endregion
914
-
915
- // #region Work
916
-
917
- async function asyncWork(
918
- initial: unknown,
919
- functions: GenericCallback[],
920
- flow: boolean,
921
- ): Promise<unknown> {
922
- const {length} = functions;
923
-
924
- let transformed = unwrapValue(initial);
925
-
926
- for (let index = 0; index < length; index += 1) {
927
- const fn = functions[index];
928
-
929
- const value =
930
- flow && index === 0 && Array.isArray(initial)
931
- ? await fn(...(initial as unknown[]))
932
- : await fn(transformed);
933
-
934
- transformed = unwrapValue(value);
935
- }
936
-
937
- return transformed;
938
- }
939
-
940
- function unwrapValue(value: unknown, flow?: boolean, nested?: boolean): unknown {
941
- if (typeof value === 'function') {
942
- if (nested != null) {
943
- throw new TypeError(MESSAGE_NESTING);
944
- }
945
-
946
- return unwrapValue(value(), flow, true);
947
- }
948
-
949
- if (flow != null && value instanceof Promise) {
950
- throw new TypeError(flow ? MESSAGE_FLOW_PROMISE : MESSAGE_PIPE_PROMISE);
951
- }
952
-
953
- if (isError(value)) {
954
- throw value.error;
955
- }
956
-
957
- return isOk(value) ? value.value : value;
958
- }
959
-
960
- function work(initial: unknown, functions: GenericCallback[], flow: boolean): unknown {
961
- const {length} = functions;
962
-
963
- let transformed = unwrapValue(initial, flow);
964
-
965
- for (let index = 0; index < length; index += 1) {
966
- const fn = functions[index];
967
-
968
- const value =
969
- flow && index === 0 && Array.isArray(initial)
970
- ? fn(...(initial as unknown[]))
971
- : fn(transformed);
972
-
973
- transformed = unwrapValue(value, flow);
974
- }
975
-
976
- return transformed;
977
- }
978
-
979
- // #endregion
980
-
981
- // #endregion
982
-
983
- // #region Variables
984
-
985
- const MESSAGE_FLOW_ARRAY = 'Flow expected to receive an array of functions';
986
-
987
- const MESSAGE_FLOW_PROMISE = 'Synchronous Flow received a promise. Use `flow.async` instead.';
988
-
989
- const MESSAGE_NESTING = 'Return values are too deeply nested.';
990
-
991
- const MESSAGE_PIPE_ARRAY = 'Pipe expected to receive an array of functions';
992
-
993
- const MESSAGE_PIPE_PROMISE = 'Synchronous Pipe received a promise. Use `pipe.async` instead.';
994
-
995
- const assertFlowFunctions: Asserter<Function[]> = assert.condition(
996
- value => Array.isArray(value) && value.every(item => typeof item === 'function'),
997
- MESSAGE_FLOW_ARRAY,
998
- TypeError,
999
- );
1000
-
1001
- const assertPipeFunctions: Asserter<Function[]> = assert.condition(
1002
- value => Array.isArray(value) && value.every(item => typeof item === 'function'),
1003
- MESSAGE_PIPE_ARRAY,
1004
- TypeError,
1005
- );
1006
-
1007
- // #endregion