fp-pack 0.6.0 → 0.7.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 (42) hide show
  1. package/README.md +1 -0
  2. package/dist/fp-pack.umd.js +1 -1
  3. package/dist/fp-pack.umd.js.map +1 -1
  4. package/dist/implement/async/pipeAsync.d.ts +11 -0
  5. package/dist/implement/async/pipeAsync.d.ts.map +1 -1
  6. package/dist/implement/async/pipeAsync.mjs.map +1 -1
  7. package/dist/implement/async/pipeAsyncSideEffect.d.ts +11 -0
  8. package/dist/implement/async/pipeAsyncSideEffect.d.ts.map +1 -1
  9. package/dist/implement/async/pipeAsyncSideEffect.mjs.map +1 -1
  10. package/dist/implement/composition/compose.d.ts +25 -9
  11. package/dist/implement/composition/compose.d.ts.map +1 -1
  12. package/dist/implement/composition/compose.mjs.map +1 -1
  13. package/dist/implement/composition/compose.type-test.d.ts +35 -0
  14. package/dist/implement/composition/compose.type-test.d.ts.map +1 -0
  15. package/dist/implement/composition/compose.util.type-test.d.ts +31 -0
  16. package/dist/implement/composition/compose.util.type-test.d.ts.map +1 -0
  17. package/dist/implement/composition/index.d.ts +1 -0
  18. package/dist/implement/composition/index.d.ts.map +1 -1
  19. package/dist/implement/composition/pipe.type-test.d.ts +110 -0
  20. package/dist/implement/composition/pipe.type-test.d.ts.map +1 -1
  21. package/dist/implement/composition/pipe.util.type-test.d.ts +75 -0
  22. package/dist/implement/composition/pipe.util.type-test.d.ts.map +1 -0
  23. package/dist/implement/composition/tap0.d.ts +6 -0
  24. package/dist/implement/composition/tap0.d.ts.map +1 -0
  25. package/dist/implement/composition/tap0.mjs +9 -0
  26. package/dist/implement/composition/tap0.mjs.map +1 -0
  27. package/dist/index.mjs +230 -228
  28. package/dist/index.mjs.map +1 -1
  29. package/dist/skills/fp-pack/SKILL.md +2 -1
  30. package/dist/skills/fp-pack.md +2 -1
  31. package/package.json +1 -1
  32. package/src/implement/async/pipeAsync.ts +71 -0
  33. package/src/implement/async/pipeAsyncSideEffect.ts +74 -0
  34. package/src/implement/composition/compose.test.ts +14 -0
  35. package/src/implement/composition/compose.ts +133 -21
  36. package/src/implement/composition/compose.type-test.ts +109 -0
  37. package/src/implement/composition/compose.util.type-test.ts +128 -0
  38. package/src/implement/composition/index.ts +1 -0
  39. package/src/implement/composition/pipe.type-test.ts +252 -0
  40. package/src/implement/composition/pipe.util.type-test.ts +256 -0
  41. package/src/implement/composition/tap0.test.ts +16 -0
  42. package/src/implement/composition/tap0.ts +10 -0
@@ -25,6 +25,21 @@ export const purePipe = pipe(
25
25
  type PurePipeExpected = (input: number) => string;
26
26
  export type PipePureIsStrict = Expect<Equal<typeof purePipe, PurePipeExpected>>;
27
27
 
28
+ export const purePipeZero = pipe(() => 3, (value: number) => value + 1);
29
+
30
+ type PurePipeZeroExpected = () => number;
31
+ export type PipePureZeroIsStrict = Expect<Equal<typeof purePipeZero, PurePipeZeroExpected>>;
32
+
33
+ export const purePipeZeroValue = purePipeZero();
34
+
35
+ type PurePipeZeroValueExpected = number;
36
+ export type PipePureZeroValueIsStrict = Expect<Equal<typeof purePipeZeroValue, PurePipeZeroValueExpected>>;
37
+
38
+ export const purePipeValue = purePipe(1);
39
+
40
+ type PurePipeValueExpected = string;
41
+ export type PipePureValueIsStrict = Expect<Equal<typeof purePipeValue, PurePipeValueExpected>>;
42
+
28
43
  export const purePipeSix = pipe(
29
44
  (value: number) => value + 1,
30
45
  (value) => value * 2,
@@ -78,6 +93,16 @@ export type PipeFromTenValueNoInputIsStrict = Expect<
78
93
  Equal<typeof pipeFromTenValueNoInput, PipeFromTenValueNoInputExpected>
79
94
  >;
80
95
 
96
+ export const pipeFromNoInput = pipe(from(1));
97
+
98
+ type PipeFromNoInputExpected = (input?: unknown) => number;
99
+ export type PipeFromNoInputIsStrict = Expect<Equal<typeof pipeFromNoInput, PipeFromNoInputExpected>>;
100
+
101
+ export const pipeFromNoInputValue = pipeFromNoInput();
102
+
103
+ type PipeFromNoInputValueExpected = number;
104
+ export type PipeFromNoInputValueIsStrict = Expect<Equal<typeof pipeFromNoInputValue, PipeFromNoInputValueExpected>>;
105
+
81
106
  export const pipeWithSideEffectInput = pipeSideEffect(
82
107
  (value: number) => value + 1,
83
108
  (value) => value * 2,
@@ -89,6 +114,25 @@ export const pipeWithSideEffectValue = pipeWithSideEffectInput(sideEffectInput);
89
114
  type PipeExpected = (input: number | SideEffect<any>) => string | SideEffect<any>;
90
115
  export type PipeAcceptsSideEffectInput = Expect<Equal<typeof pipeWithSideEffectInput, PipeExpected>>;
91
116
 
117
+ export const pipeSideEffectZero = pipeSideEffect(() => 1, (value: number) => value + 1);
118
+
119
+ type PipeSideEffectZeroExpected = () => number | SideEffect<any>;
120
+ export type PipeSideEffectZeroIsStrict = Expect<Equal<typeof pipeSideEffectZero, PipeSideEffectZeroExpected>>;
121
+
122
+ export const pipeSideEffectZeroValue = pipeSideEffectZero();
123
+
124
+ type PipeSideEffectZeroValueExpected = number | SideEffect<any>;
125
+ export type PipeSideEffectZeroValueIsStrict = Expect<
126
+ Equal<typeof pipeSideEffectZeroValue, PipeSideEffectZeroValueExpected>
127
+ >;
128
+
129
+ export const pipeWithSideEffectValueInput = pipeWithSideEffectInput(1);
130
+
131
+ type PipeWithSideEffectValueInputExpected = string | SideEffect<any>;
132
+ export type PipeSideEffectValueInputIsStrict = Expect<
133
+ Equal<typeof pipeWithSideEffectValueInput, PipeWithSideEffectValueInputExpected>
134
+ >;
135
+
92
136
  export const pipeSideEffectSix = pipeSideEffect(
93
137
  (value: number) => value + 1,
94
138
  (value) => value * 2,
@@ -144,6 +188,20 @@ export type PipeSideEffectFromTenValueNoInputIsStrict = Expect<
144
188
  Equal<typeof pipeSideEffectFromTenValueNoInput, PipeSideEffectFromTenValueNoInputExpected>
145
189
  >;
146
190
 
191
+ export const pipeSideEffectFromNoInput = pipeSideEffect(from(1));
192
+
193
+ type PipeSideEffectFromNoInputExpected = (input?: unknown) => number | SideEffect<any>;
194
+ export type PipeSideEffectFromNoInputIsStrict = Expect<
195
+ Equal<typeof pipeSideEffectFromNoInput, PipeSideEffectFromNoInputExpected>
196
+ >;
197
+
198
+ export const pipeSideEffectFromNoInputValue = pipeSideEffectFromNoInput();
199
+
200
+ type PipeSideEffectFromNoInputValueExpected = number | SideEffect<any>;
201
+ export type PipeSideEffectFromNoInputValueIsStrict = Expect<
202
+ Equal<typeof pipeSideEffectFromNoInputValue, PipeSideEffectFromNoInputValueExpected>
203
+ >;
204
+
147
205
  export const purePipeAsync = pipeAsync(
148
206
  (value: number) => value + 1,
149
207
  async (value) => value * 2,
@@ -153,6 +211,23 @@ export const purePipeAsync = pipeAsync(
153
211
  type PurePipeAsyncExpected = (input: number) => Promise<string>;
154
212
  export type PipeAsyncPureIsStrict = Expect<Equal<typeof purePipeAsync, PurePipeAsyncExpected>>;
155
213
 
214
+ export const purePipeAsyncZero = pipeAsync(() => 1, async (value: number) => value + 1);
215
+
216
+ type PurePipeAsyncZeroExpected = () => Promise<number>;
217
+ export type PipeAsyncPureZeroIsStrict = Expect<Equal<typeof purePipeAsyncZero, PurePipeAsyncZeroExpected>>;
218
+
219
+ export const purePipeAsyncZeroValue = purePipeAsyncZero();
220
+
221
+ type PurePipeAsyncZeroValueExpected = Promise<number>;
222
+ export type PipeAsyncPureZeroValueIsStrict = Expect<
223
+ Equal<typeof purePipeAsyncZeroValue, PurePipeAsyncZeroValueExpected>
224
+ >;
225
+
226
+ export const purePipeAsyncValue = purePipeAsync(1);
227
+
228
+ type PurePipeAsyncValueExpected = Promise<string>;
229
+ export type PipeAsyncPureValueIsStrict = Expect<Equal<typeof purePipeAsyncValue, PurePipeAsyncValueExpected>>;
230
+
156
231
  export const purePipeAsyncSix = pipeAsync(
157
232
  (value: number) => value + 1,
158
233
  async (value) => value * 2,
@@ -208,6 +283,18 @@ export type PipeAsyncFromTenValueNoInputIsStrict = Expect<
208
283
  Equal<typeof pipeAsyncFromTenValueNoInput, PipeAsyncFromTenValueNoInputExpected>
209
284
  >;
210
285
 
286
+ export const pipeAsyncFromNoInput = pipeAsync(from(1));
287
+
288
+ type PipeAsyncFromNoInputExpected = (input?: unknown) => Promise<number>;
289
+ export type PipeAsyncFromNoInputIsStrict = Expect<Equal<typeof pipeAsyncFromNoInput, PipeAsyncFromNoInputExpected>>;
290
+
291
+ export const pipeAsyncFromNoInputValue = pipeAsyncFromNoInput();
292
+
293
+ type PipeAsyncFromNoInputValueExpected = Promise<number>;
294
+ export type PipeAsyncFromNoInputValueIsStrict = Expect<
295
+ Equal<typeof pipeAsyncFromNoInputValue, PipeAsyncFromNoInputValueExpected>
296
+ >;
297
+
211
298
  export const pipeAsyncWithSideEffectInput = pipeAsyncSideEffect(
212
299
  (value: number) => value + 1,
213
300
  async (value) => value * 2,
@@ -221,6 +308,27 @@ export type PipeAsyncAcceptsSideEffectInput = Expect<
221
308
  Equal<typeof pipeAsyncWithSideEffectInput, PipeAsyncExpected>
222
309
  >;
223
310
 
311
+ export const pipeAsyncSideEffectZero = pipeAsyncSideEffect(() => 1, async (value: number) => value + 1);
312
+
313
+ type PipeAsyncSideEffectZeroExpected = () => Promise<number | SideEffect<any>>;
314
+ export type PipeAsyncSideEffectZeroIsStrict = Expect<
315
+ Equal<typeof pipeAsyncSideEffectZero, PipeAsyncSideEffectZeroExpected>
316
+ >;
317
+
318
+ export const pipeAsyncSideEffectZeroValue = pipeAsyncSideEffectZero();
319
+
320
+ type PipeAsyncSideEffectZeroValueExpected = Promise<number | SideEffect<any>>;
321
+ export type PipeAsyncSideEffectZeroValueIsStrict = Expect<
322
+ Equal<typeof pipeAsyncSideEffectZeroValue, PipeAsyncSideEffectZeroValueExpected>
323
+ >;
324
+
325
+ export const pipeAsyncWithSideEffectValueInput = pipeAsyncWithSideEffectInput(1);
326
+
327
+ type PipeAsyncWithSideEffectValueInputExpected = Promise<string | SideEffect<any>>;
328
+ export type PipeAsyncSideEffectValueInputIsStrict = Expect<
329
+ Equal<typeof pipeAsyncWithSideEffectValueInput, PipeAsyncWithSideEffectValueInputExpected>
330
+ >;
331
+
224
332
  export const pipeAsyncSideEffectSix = pipeAsyncSideEffect(
225
333
  (value: number) => value + 1,
226
334
  async (value) => value * 2,
@@ -280,6 +388,20 @@ export type PipeAsyncSideEffectFromTenValueNoInputIsStrict = Expect<
280
388
  Equal<typeof pipeAsyncSideEffectFromTenValueNoInput, PipeAsyncSideEffectFromTenValueNoInputExpected>
281
389
  >;
282
390
 
391
+ export const pipeAsyncSideEffectFromNoInput = pipeAsyncSideEffect(from(1));
392
+
393
+ type PipeAsyncSideEffectFromNoInputExpected = (input?: unknown) => Promise<number | SideEffect<any>>;
394
+ export type PipeAsyncSideEffectFromNoInputIsStrict = Expect<
395
+ Equal<typeof pipeAsyncSideEffectFromNoInput, PipeAsyncSideEffectFromNoInputExpected>
396
+ >;
397
+
398
+ export const pipeAsyncSideEffectFromNoInputValue = pipeAsyncSideEffectFromNoInput();
399
+
400
+ type PipeAsyncSideEffectFromNoInputValueExpected = Promise<number | SideEffect<any>>;
401
+ export type PipeAsyncSideEffectFromNoInputValueIsStrict = Expect<
402
+ Equal<typeof pipeAsyncSideEffectFromNoInputValue, PipeAsyncSideEffectFromNoInputValueExpected>
403
+ >;
404
+
283
405
  export const strictPipeSideEffect = pipeSideEffectStrict(
284
406
  (value: number) => value + 1,
285
407
  (value) => (value > 1 ? value : SideEffect.of(() => 'LOW' as const)),
@@ -288,6 +410,11 @@ export const strictPipeSideEffect = pipeSideEffectStrict(
288
410
 
289
411
  export const strictPipeSideEffectResult = strictPipeSideEffect(1);
290
412
 
413
+ type StrictPipeSideEffectResultExpected = number | SideEffect<'LOW' | 0>;
414
+ export type PipeSideEffectStrictResultIsStrict = Expect<
415
+ Equal<typeof strictPipeSideEffectResult, StrictPipeSideEffectResultExpected>
416
+ >;
417
+
291
418
  type StrictSideEffectEffects = EffectUnion<typeof strictPipeSideEffectResult>;
292
419
  type StrictSideEffectEffectsExpected = 'LOW' | 0;
293
420
  export type PipeSideEffectStrictEffects = Expect<Equal<StrictSideEffectEffects, StrictSideEffectEffectsExpected>>;
@@ -305,8 +432,30 @@ export type PipeSideEffectStrictRunPipeResultIsStrict = Expect<
305
432
  Equal<typeof strictPipeSideEffectRunResult, StrictPipeSideEffectRunExpected>
306
433
  >;
307
434
 
435
+ export const strictPipeSideEffectZero = pipeSideEffectStrict(
436
+ () => 1,
437
+ (value: number) => (value > 0 ? value : SideEffect.of(() => 'LOW' as const))
438
+ );
439
+
440
+ type StrictPipeSideEffectZeroExpected = () => number | SideEffect<'LOW'>;
441
+ export type PipeSideEffectStrictZeroIsStrict = Expect<
442
+ Equal<typeof strictPipeSideEffectZero, StrictPipeSideEffectZeroExpected>
443
+ >;
444
+
445
+ export const strictPipeSideEffectZeroValue = strictPipeSideEffectZero();
446
+
447
+ type StrictPipeSideEffectZeroValueExpected = number | SideEffect<'LOW'>;
448
+ export type PipeSideEffectStrictZeroValueIsStrict = Expect<
449
+ Equal<typeof strictPipeSideEffectZeroValue, StrictPipeSideEffectZeroValueExpected>
450
+ >;
451
+
308
452
  export const strictPipeSideEffectInput = strictPipeSideEffect(SideEffect.of(() => 'INPUT' as const));
309
453
 
454
+ type StrictPipeSideEffectInputExpected = number | SideEffect<'LOW' | 0 | 'INPUT'>;
455
+ export type PipeSideEffectStrictInputIsStrict = Expect<
456
+ Equal<typeof strictPipeSideEffectInput, StrictPipeSideEffectInputExpected>
457
+ >;
458
+
310
459
  type StrictSideEffectInputEffects = EffectUnion<typeof strictPipeSideEffectInput>;
311
460
  type StrictSideEffectInputEffectsExpected = 'LOW' | 0 | 'INPUT';
312
461
  export type PipeSideEffectStrictInputEffects = Expect<
@@ -370,6 +519,11 @@ export const strictPipeSideEffectFromTen = pipeSideEffectStrict(
370
519
 
371
520
  export const strictPipeSideEffectFromTenResult = strictPipeSideEffectFromTen('input');
372
521
 
522
+ type StrictSideEffectFromTenResultExpected = number | SideEffect<'LOW' | 'MID' | 0>;
523
+ export type PipeSideEffectStrictFromTenResultIsStrict = Expect<
524
+ Equal<typeof strictPipeSideEffectFromTenResult, StrictSideEffectFromTenResultExpected>
525
+ >;
526
+
373
527
  type StrictFromTenEffects = EffectUnion<typeof strictPipeSideEffectFromTenResult>;
374
528
  type StrictFromTenEffectsExpected = 'LOW' | 'MID' | 0;
375
529
  export type PipeSideEffectStrictFromTenEffects = Expect<
@@ -382,6 +536,11 @@ export type PipeSideEffectStrictFromTenValue = Expect<Equal<StrictFromTenValue,
382
536
 
383
537
  export const strictPipeSideEffectFromTenResultNoInput = strictPipeSideEffectFromTen();
384
538
 
539
+ type StrictSideEffectFromTenNoInputExpected = number | SideEffect<'LOW' | 'MID' | 0>;
540
+ export type PipeSideEffectStrictFromTenNoInputIsStrict = Expect<
541
+ Equal<typeof strictPipeSideEffectFromTenResultNoInput, StrictSideEffectFromTenNoInputExpected>
542
+ >;
543
+
385
544
  type StrictFromTenNoInputEffects = EffectUnion<typeof strictPipeSideEffectFromTenResultNoInput>;
386
545
  type StrictFromTenNoInputEffectsExpected = 'LOW' | 'MID' | 0;
387
546
  export type PipeSideEffectStrictFromTenNoInputEffects = Expect<
@@ -394,6 +553,23 @@ export type PipeSideEffectStrictFromTenNoInputValue = Expect<
394
553
  Equal<StrictFromTenNoInputValue, StrictFromTenNoInputValueExpected>
395
554
  >;
396
555
 
556
+ export const strictPipeSideEffectFromNoInput = pipeSideEffectStrict(from(1));
557
+
558
+ type StrictPipeSideEffectFromNoInputExpected = {
559
+ (input?: unknown): number | SideEffect<never>;
560
+ <EIn>(input?: unknown | SideEffect<EIn>): number | SideEffect<EIn>;
561
+ };
562
+ export type PipeSideEffectStrictFromNoInputIsStrict = Expect<
563
+ Equal<typeof strictPipeSideEffectFromNoInput, StrictPipeSideEffectFromNoInputExpected>
564
+ >;
565
+
566
+ export const strictPipeSideEffectFromNoInputValue = strictPipeSideEffectFromNoInput();
567
+
568
+ type StrictPipeSideEffectFromNoInputValueExpected = number | SideEffect<never>;
569
+ export type PipeSideEffectStrictFromNoInputValueIsStrict = Expect<
570
+ Equal<typeof strictPipeSideEffectFromNoInputValue, StrictPipeSideEffectFromNoInputValueExpected>
571
+ >;
572
+
397
573
  export const strictPipeAsyncSideEffect = pipeAsyncSideEffectStrict(
398
574
  (value: number) => value + 1,
399
575
  async (value) => (value > 1 ? value : SideEffect.of(() => 'LOW' as const)),
@@ -402,6 +578,11 @@ export const strictPipeAsyncSideEffect = pipeAsyncSideEffectStrict(
402
578
 
403
579
  export const strictPipeAsyncSideEffectResult = strictPipeAsyncSideEffect(1);
404
580
 
581
+ type StrictPipeAsyncSideEffectResultExpected = Promise<number | SideEffect<'LOW' | 0>>;
582
+ export type PipeAsyncSideEffectStrictResultIsStrict = Expect<
583
+ Equal<typeof strictPipeAsyncSideEffectResult, StrictPipeAsyncSideEffectResultExpected>
584
+ >;
585
+
405
586
  type StrictPipeAsyncResolved = Awaited<typeof strictPipeAsyncSideEffectResult>;
406
587
  type StrictPipeAsyncEffects = EffectUnion<StrictPipeAsyncResolved>;
407
588
  type StrictPipeAsyncEffectsExpected = 'LOW' | 0;
@@ -415,6 +596,23 @@ export type PipeAsyncSideEffectStrictValue = Expect<
415
596
  Equal<StrictPipeAsyncValue, StrictPipeAsyncValueExpected>
416
597
  >;
417
598
 
599
+ export const strictPipeAsyncSideEffectZero = pipeAsyncSideEffectStrict(
600
+ () => 1,
601
+ async (value: number) => (value > 0 ? value : SideEffect.of(() => 'LOW' as const))
602
+ );
603
+
604
+ type StrictPipeAsyncSideEffectZeroExpected = () => Promise<number | SideEffect<'LOW'>>;
605
+ export type PipeAsyncSideEffectStrictZeroIsStrict = Expect<
606
+ Equal<typeof strictPipeAsyncSideEffectZero, StrictPipeAsyncSideEffectZeroExpected>
607
+ >;
608
+
609
+ export const strictPipeAsyncSideEffectZeroValue = strictPipeAsyncSideEffectZero();
610
+
611
+ type StrictPipeAsyncSideEffectZeroValueExpected = Promise<number | SideEffect<'LOW'>>;
612
+ export type PipeAsyncSideEffectStrictZeroValueIsStrict = Expect<
613
+ Equal<typeof strictPipeAsyncSideEffectZeroValue, StrictPipeAsyncSideEffectZeroValueExpected>
614
+ >;
615
+
418
616
  export const strictPipeAsyncSideEffectSix = pipeAsyncSideEffectStrict(
419
617
  (value: number) => value + 1,
420
618
  async (value) => (value > 2 ? value : SideEffect.of(() => 'LOW' as const)),
@@ -482,6 +680,11 @@ export const strictPipeAsyncSideEffectFromTen = pipeAsyncSideEffectStrict(
482
680
 
483
681
  export const strictPipeAsyncSideEffectFromTenResult = strictPipeAsyncSideEffectFromTen('input');
484
682
 
683
+ type StrictAsyncFromTenResultExpected = Promise<number | SideEffect<'LOW' | 'MID' | 0>>;
684
+ export type PipeAsyncSideEffectStrictFromTenResultIsStrict = Expect<
685
+ Equal<typeof strictPipeAsyncSideEffectFromTenResult, StrictAsyncFromTenResultExpected>
686
+ >;
687
+
485
688
  type StrictAsyncFromTenResolved = Awaited<typeof strictPipeAsyncSideEffectFromTenResult>;
486
689
  type StrictAsyncFromTenEffects = EffectUnion<StrictAsyncFromTenResolved>;
487
690
  type StrictAsyncFromTenEffectsExpected = 'LOW' | 'MID' | 0;
@@ -497,6 +700,11 @@ export type PipeAsyncSideEffectStrictFromTenValue = Expect<
497
700
 
498
701
  export const strictPipeAsyncSideEffectFromTenResultNoInput = strictPipeAsyncSideEffectFromTen();
499
702
 
703
+ type StrictAsyncFromTenNoInputResultExpected = Promise<number | SideEffect<'LOW' | 'MID' | 0>>;
704
+ export type PipeAsyncSideEffectStrictFromTenNoInputIsStrict = Expect<
705
+ Equal<typeof strictPipeAsyncSideEffectFromTenResultNoInput, StrictAsyncFromTenNoInputResultExpected>
706
+ >;
707
+
500
708
  type StrictAsyncFromTenNoInputResolved = Awaited<typeof strictPipeAsyncSideEffectFromTenResultNoInput>;
501
709
  type StrictAsyncFromTenNoInputEffects = EffectUnion<StrictAsyncFromTenNoInputResolved>;
502
710
  type StrictAsyncFromTenNoInputEffectsExpected = 'LOW' | 'MID' | 0;
@@ -509,3 +717,47 @@ type StrictAsyncFromTenNoInputValueExpected = number;
509
717
  export type PipeAsyncSideEffectStrictFromTenNoInputValue = Expect<
510
718
  Equal<StrictAsyncFromTenNoInputValue, StrictAsyncFromTenNoInputValueExpected>
511
719
  >;
720
+
721
+ export const strictPipeAsyncSideEffectFromNoInput = pipeAsyncSideEffectStrict(from(1));
722
+
723
+ type StrictAsyncSideEffectFromNoInputExpected = {
724
+ (input?: unknown): Promise<number | SideEffect<never>>;
725
+ <EIn>(input?: unknown | SideEffect<EIn>): Promise<number | SideEffect<EIn>>;
726
+ };
727
+ export type PipeAsyncSideEffectStrictFromNoInputIsStrict = Expect<
728
+ Equal<typeof strictPipeAsyncSideEffectFromNoInput, StrictAsyncSideEffectFromNoInputExpected>
729
+ >;
730
+
731
+ export const strictPipeAsyncSideEffectFromNoInputValue = strictPipeAsyncSideEffectFromNoInput();
732
+
733
+ type StrictAsyncSideEffectFromNoInputValueExpected = Promise<number | SideEffect<never>>;
734
+ export type PipeAsyncSideEffectStrictFromNoInputValueIsStrict = Expect<
735
+ Equal<typeof strictPipeAsyncSideEffectFromNoInputValue, StrictAsyncSideEffectFromNoInputValueExpected>
736
+ >;
737
+
738
+ // Negative cases: input required when not using from/zero-arity.
739
+ // @ts-expect-error input required for unary pipe
740
+ purePipe();
741
+ // @ts-expect-error input required for unary pipeSideEffect
742
+ pipeWithSideEffectInput();
743
+ // @ts-expect-error input required for unary pipeSideEffectStrict
744
+ strictPipeSideEffect();
745
+ // @ts-expect-error input required for unary pipeAsync
746
+ purePipeAsync();
747
+ // @ts-expect-error input required for unary pipeAsyncSideEffect
748
+ pipeAsyncWithSideEffectInput();
749
+ // @ts-expect-error input required for unary pipeAsyncSideEffectStrict
750
+ strictPipeAsyncSideEffect();
751
+
752
+ // @ts-expect-error input required for direct pipe call
753
+ pipe((value: number) => value + 1)();
754
+ // @ts-expect-error input required for direct pipeSideEffect call
755
+ pipeSideEffect((value: number) => value + 1)();
756
+ // @ts-expect-error input required for direct pipeSideEffectStrict call
757
+ pipeSideEffectStrict((value: number) => value + 1)();
758
+ // @ts-expect-error input required for direct pipeAsync call
759
+ pipeAsync((value: number) => value + 1)();
760
+ // @ts-expect-error input required for direct pipeAsyncSideEffect call
761
+ pipeAsyncSideEffect((value: number) => value + 1)();
762
+ // @ts-expect-error input required for direct pipeAsyncSideEffectStrict call
763
+ pipeAsyncSideEffectStrict((value: number) => value + 1)();
@@ -0,0 +1,256 @@
1
+ import SideEffect from './sideEffect';
2
+ import pipe from './pipe';
3
+ import pipeSideEffect from './pipeSideEffect';
4
+ import pipeSideEffectStrict from './pipeSideEffectStrict';
5
+ import tap from './tap';
6
+ import pipeAsync from '../async/pipeAsync';
7
+ import pipeAsyncSideEffect from '../async/pipeAsyncSideEffect';
8
+ import pipeAsyncSideEffectStrict from '../async/pipeAsyncSideEffectStrict';
9
+ import filter from '../array/filter';
10
+ import flattenDeep from '../array/flattenDeep';
11
+ import map from '../array/map';
12
+ import sum from '../math/sum';
13
+ import gt from '../equality/gt';
14
+ import isEmpty from '../equality/isEmpty';
15
+ import when from '../control/when';
16
+ import ifElse from '../control/ifElse';
17
+ import log from '../debug/log';
18
+ import prop from '../object/prop';
19
+ import mergeAll from '../object/mergeAll';
20
+ import getOrElse from '../nullable/getOrElse';
21
+ import mapMaybe from '../nullable/mapMaybe';
22
+ import join from '../string/join';
23
+ import trim from '../string/trim';
24
+ import toUpper from '../string/toUpper';
25
+ import streamFilter from '../../stream/filter';
26
+ import streamMap from '../../stream/map';
27
+ import streamRange from '../../stream/range';
28
+ import streamReduce from '../../stream/reduce';
29
+ import streamToArray from '../../stream/toArray';
30
+
31
+ type Equal<A, B> = (<T>() => T extends A ? 1 : 2) extends (<T>() => T extends B ? 1 : 2)
32
+ ? true
33
+ : false;
34
+ type Expect<T extends true> = T;
35
+
36
+ type User = {
37
+ name?: string;
38
+ };
39
+
40
+ type TagOwner = {
41
+ tags?: Array<string | null>;
42
+ };
43
+
44
+ type Config = {
45
+ value?: number;
46
+ };
47
+
48
+ const getName = prop('name') as (user: User) => string | undefined;
49
+ const getTags = prop('tags') as (owner: TagOwner) => Array<string | null> | undefined;
50
+ const mergeConfig = mergeAll as (configs: Config[]) => Config;
51
+ const getValue = prop('value') as (config: Config) => number | undefined;
52
+ const streamMapNumber = streamMap((value: number) => value + 1) as (iterable: Iterable<number>) => IterableIterator<
53
+ number
54
+ >;
55
+ const streamFilterNumber = streamFilter((value: number) => value > 1) as (
56
+ iterable: Iterable<number>
57
+ ) => IterableIterator<number>;
58
+ const streamReduceNumber = streamReduce((acc: number, value: number) => acc + value, 0) as (
59
+ iterable: Iterable<number>
60
+ ) => number;
61
+ const streamMapAsyncNumber = streamMap(async (value: number) => value + 1) as (
62
+ iterable: Iterable<number>
63
+ ) => IterableIterator<Promise<number>>;
64
+
65
+ export const pipeArrayControlString = pipe(
66
+ flattenDeep<number>,
67
+ filter(gt(1)),
68
+ map((value: number) => value * 2),
69
+ sum,
70
+ when(gt(10), (value) => value + 1),
71
+ (value) => `${value}`,
72
+ trim,
73
+ toUpper,
74
+ log('total')
75
+ );
76
+
77
+ type PipeArrayControlStringExpected = (input: any[]) => string;
78
+ export type PipeArrayControlStringIsStrict = Expect<
79
+ Equal<typeof pipeArrayControlString, PipeArrayControlStringExpected>
80
+ >;
81
+
82
+ export const pipeObjectNullableControl = pipe(
83
+ getName,
84
+ getOrElse(''),
85
+ ifElse(
86
+ (value: string) => value.length > 0,
87
+ toUpper,
88
+ () => 'UNKNOWN'
89
+ ),
90
+ tap((value: string) => value.length)
91
+ );
92
+
93
+ type PipeObjectNullableControlExpected = (input: User) => string;
94
+ export type PipeObjectNullableControlIsStrict = Expect<
95
+ Equal<typeof pipeObjectNullableControl, PipeObjectNullableControlExpected>
96
+ >;
97
+
98
+ export const pipeSideEffectTags = pipeSideEffect(
99
+ getTags,
100
+ getOrElse<Array<string | null>>([]),
101
+ mapMaybe((tag) => (tag ? tag.trim() : null)),
102
+ map((tag) => tag.toUpperCase()),
103
+ join('|'),
104
+ (value) => (isEmpty(value) ? SideEffect.of(() => 'EMPTY' as const) : value)
105
+ );
106
+
107
+ type PipeSideEffectTagsExpected = (input: TagOwner | SideEffect<any>) => string | SideEffect<any>;
108
+ export type PipeSideEffectTagsIsStrict = Expect<Equal<typeof pipeSideEffectTags, PipeSideEffectTagsExpected>>;
109
+
110
+ export const pipeSideEffectStrictConfig = pipeSideEffectStrict(
111
+ mergeConfig,
112
+ getValue,
113
+ getOrElse(0),
114
+ when(gt(0), (value) => value + 1),
115
+ (value) => (value > 0 ? value : SideEffect.of(() => 'NO_VALUE' as const)),
116
+ (value) => value + 1
117
+ );
118
+
119
+ export const pipeSideEffectStrictConfigValue = pipeSideEffectStrictConfig([{ value: 1 }]);
120
+
121
+ type PipeSideEffectStrictConfigValueExpected = number | SideEffect<'NO_VALUE'>;
122
+ export type PipeSideEffectStrictConfigValueIsStrict = Expect<
123
+ Equal<typeof pipeSideEffectStrictConfigValue, PipeSideEffectStrictConfigValueExpected>
124
+ >;
125
+
126
+ export const pipeSideEffectStrictConfigInput = pipeSideEffectStrictConfig(SideEffect.of(() => 'INPUT' as const));
127
+
128
+ type PipeSideEffectStrictConfigInputExpected = number | SideEffect<'NO_VALUE' | 'INPUT'>;
129
+ export type PipeSideEffectStrictConfigInputIsStrict = Expect<
130
+ Equal<typeof pipeSideEffectStrictConfigInput, PipeSideEffectStrictConfigInputExpected>
131
+ >;
132
+
133
+ export const pipeAsyncUserLabel = pipeAsync(
134
+ getName,
135
+ getOrElse(''),
136
+ async (value) => value.trim(),
137
+ ifElse(
138
+ (value: string) => value.length > 0,
139
+ toUpper,
140
+ () => 'UNKNOWN'
141
+ ),
142
+ log('label')
143
+ );
144
+
145
+ type PipeAsyncUserLabelExpected = (input: User) => Promise<string>;
146
+ export type PipeAsyncUserLabelIsStrict = Expect<Equal<typeof pipeAsyncUserLabel, PipeAsyncUserLabelExpected>>;
147
+
148
+ export const pipeAsyncSideEffectTags = pipeAsyncSideEffect(
149
+ getTags,
150
+ getOrElse<Array<string | null>>([]),
151
+ mapMaybe((tag) => (tag ? tag.trim() : null)),
152
+ async (tags) => tags.map((tag) => tag.toUpperCase()),
153
+ join('|'),
154
+ (value) => (isEmpty(value) ? SideEffect.of(() => 'EMPTY' as const) : value)
155
+ );
156
+
157
+ type PipeAsyncSideEffectTagsExpected = (input: TagOwner | SideEffect<any>) => Promise<string | SideEffect<any>>;
158
+ export type PipeAsyncSideEffectTagsIsStrict = Expect<
159
+ Equal<typeof pipeAsyncSideEffectTags, PipeAsyncSideEffectTagsExpected>
160
+ >;
161
+
162
+ export const pipeAsyncSideEffectStrictConfig = pipeAsyncSideEffectStrict(
163
+ mergeConfig,
164
+ getValue,
165
+ getOrElse(0),
166
+ async (value) => value + 1,
167
+ (value) => (value > 0 ? value : SideEffect.of(() => 'NO_VALUE' as const)),
168
+ async (value) => value + 1
169
+ );
170
+
171
+ export const pipeAsyncSideEffectStrictConfigValue = pipeAsyncSideEffectStrictConfig([{ value: 1 }]);
172
+
173
+ type PipeAsyncSideEffectStrictConfigValueExpected = Promise<number | SideEffect<'NO_VALUE'>>;
174
+ export type PipeAsyncSideEffectStrictConfigValueIsStrict = Expect<
175
+ Equal<typeof pipeAsyncSideEffectStrictConfigValue, PipeAsyncSideEffectStrictConfigValueExpected>
176
+ >;
177
+
178
+ export const pipeAsyncSideEffectStrictConfigInput = pipeAsyncSideEffectStrictConfig(
179
+ SideEffect.of(() => 'INPUT' as const)
180
+ );
181
+
182
+ type PipeAsyncSideEffectStrictConfigInputExpected = Promise<number | SideEffect<'NO_VALUE' | 'INPUT'>>;
183
+ export type PipeAsyncSideEffectStrictConfigInputIsStrict = Expect<
184
+ Equal<typeof pipeAsyncSideEffectStrictConfigInput, PipeAsyncSideEffectStrictConfigInputExpected>
185
+ >;
186
+
187
+ export const pipeStreamSync = pipe(
188
+ (end: number) => streamRange(0, end),
189
+ streamMapNumber,
190
+ streamFilterNumber,
191
+ streamReduceNumber
192
+ );
193
+
194
+ type PipeStreamSyncExpected = (input: number) => number;
195
+ export type PipeStreamSyncIsStrict = Expect<Equal<typeof pipeStreamSync, PipeStreamSyncExpected>>;
196
+
197
+ export const pipeSideEffectStream = pipeSideEffect(
198
+ (end: number) => streamRange(0, end),
199
+ streamMapNumber,
200
+ streamFilterNumber,
201
+ streamReduceNumber,
202
+ (value) => (value > 0 ? value : SideEffect.of(() => 'EMPTY' as const))
203
+ );
204
+
205
+ type PipeSideEffectStreamExpected = (input: number | SideEffect<any>) => number | SideEffect<any>;
206
+ export type PipeSideEffectStreamIsStrict = Expect<Equal<typeof pipeSideEffectStream, PipeSideEffectStreamExpected>>;
207
+
208
+ export const pipeSideEffectStrictStream = pipeSideEffectStrict(
209
+ (end: number) => streamRange(0, end),
210
+ streamMapNumber,
211
+ streamFilterNumber,
212
+ streamReduceNumber,
213
+ (value) => (value > 0 ? value : SideEffect.of(() => 'EMPTY' as const))
214
+ );
215
+
216
+ export const pipeSideEffectStrictStreamValue = pipeSideEffectStrictStream(3);
217
+
218
+ type PipeSideEffectStrictStreamValueExpected = number | SideEffect<'EMPTY'>;
219
+ export type PipeSideEffectStrictStreamValueIsStrict = Expect<
220
+ Equal<typeof pipeSideEffectStrictStreamValue, PipeSideEffectStrictStreamValueExpected>
221
+ >;
222
+
223
+ export const pipeAsyncStream = pipeAsync(
224
+ (end: number) => streamRange(0, end),
225
+ streamMapAsyncNumber,
226
+ streamToArray
227
+ );
228
+
229
+ type PipeAsyncStreamExpected = (input: number) => Promise<number[]>;
230
+ export type PipeAsyncStreamIsStrict = Expect<Equal<typeof pipeAsyncStream, PipeAsyncStreamExpected>>;
231
+
232
+ export const pipeAsyncSideEffectStream = pipeAsyncSideEffect(
233
+ (end: number) => streamRange(0, end),
234
+ streamMapAsyncNumber,
235
+ streamToArray,
236
+ (value) => (value.length > 0 ? value : SideEffect.of(() => 'EMPTY' as const))
237
+ );
238
+
239
+ type PipeAsyncSideEffectStreamExpected = (input: number | SideEffect<any>) => Promise<number[] | SideEffect<any>>;
240
+ export type PipeAsyncSideEffectStreamIsStrict = Expect<
241
+ Equal<typeof pipeAsyncSideEffectStream, PipeAsyncSideEffectStreamExpected>
242
+ >;
243
+
244
+ export const pipeAsyncSideEffectStrictStream = pipeAsyncSideEffectStrict(
245
+ (end: number) => streamRange(0, end),
246
+ streamMapAsyncNumber,
247
+ streamToArray,
248
+ (value) => (value.length > 0 ? value : SideEffect.of(() => 'EMPTY' as const))
249
+ );
250
+
251
+ export const pipeAsyncSideEffectStrictStreamValue = pipeAsyncSideEffectStrictStream(3);
252
+
253
+ type PipeAsyncSideEffectStrictStreamValueExpected = Promise<number[] | SideEffect<'EMPTY'>>;
254
+ export type PipeAsyncSideEffectStrictStreamValueIsStrict = Expect<
255
+ Equal<typeof pipeAsyncSideEffectStrictStreamValue, PipeAsyncSideEffectStrictStreamValueExpected>
256
+ >;
@@ -0,0 +1,16 @@
1
+ import { vi, describe, it, expect } from 'vitest';
2
+ import tap0 from './tap0';
3
+
4
+ describe('tap0', () => {
5
+ it('runs the side effect without input', () => {
6
+ const spy = vi.fn();
7
+ tap0(spy)();
8
+
9
+ expect(spy).toHaveBeenCalledTimes(1);
10
+ });
11
+
12
+ it('returns undefined', () => {
13
+ const result = tap0(() => {})();
14
+ expect(result).toBeUndefined();
15
+ });
16
+ });
@@ -0,0 +1,10 @@
1
+ /**
2
+ * tap0 - 입력 없이 side-effect 실행
3
+ */
4
+ function tap0(fn: () => void): () => void {
5
+ return () => {
6
+ fn();
7
+ };
8
+ }
9
+
10
+ export default tap0;