fp-pack 0.5.0 → 0.6.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 (51) hide show
  1. package/README.md +16 -15
  2. package/dist/fp-pack.umd.js.map +1 -1
  3. package/dist/implement/composition/curry.d.ts +5 -5
  4. package/dist/implement/composition/curry.d.ts.map +1 -1
  5. package/dist/implement/composition/curry.mjs.map +1 -1
  6. package/dist/implement/composition/index.d.ts +3 -0
  7. package/dist/implement/composition/index.d.ts.map +1 -1
  8. package/dist/implement/composition/pipe.d.ts +3 -0
  9. package/dist/implement/composition/pipe.d.ts.map +1 -1
  10. package/dist/implement/composition/pipe.mjs.map +1 -1
  11. package/dist/implement/composition/pipe.type-test.d.ts +7 -1
  12. package/dist/implement/composition/pipe.type-test.d.ts.map +1 -1
  13. package/dist/implement/composition/sideEffect.d.ts +1 -1
  14. package/dist/implement/composition/sideEffect.d.ts.map +1 -1
  15. package/dist/implement/composition/sideEffect.mjs.map +1 -1
  16. package/dist/implement/object/assocPath.d.ts +2 -1
  17. package/dist/implement/object/assocPath.d.ts.map +1 -1
  18. package/dist/implement/object/assocPath.mjs.map +1 -1
  19. package/dist/implement/object/dissocPath.d.ts +2 -1
  20. package/dist/implement/object/dissocPath.d.ts.map +1 -1
  21. package/dist/implement/object/dissocPath.mjs.map +1 -1
  22. package/dist/implement/object/index.d.ts +1 -0
  23. package/dist/implement/object/index.d.ts.map +1 -1
  24. package/dist/implement/object/path.d.ts +4 -2
  25. package/dist/implement/object/path.d.ts.map +1 -1
  26. package/dist/implement/object/path.mjs.map +1 -1
  27. package/dist/implement/object/pathKey.d.ts +2 -0
  28. package/dist/implement/object/pathKey.d.ts.map +1 -0
  29. package/dist/implement/object/pathOr.d.ts +5 -3
  30. package/dist/implement/object/pathOr.d.ts.map +1 -1
  31. package/dist/implement/object/pathOr.mjs.map +1 -1
  32. package/dist/index.d.ts +1 -0
  33. package/dist/index.d.ts.map +1 -1
  34. package/dist/skills/fp-pack/SKILL.md +18 -16
  35. package/dist/skills/fp-pack.md +18 -16
  36. package/dist/stream/index.d.ts +1 -0
  37. package/dist/stream/index.d.ts.map +1 -1
  38. package/package.json +1 -1
  39. package/src/implement/composition/curry.ts +5 -5
  40. package/src/implement/composition/index.ts +3 -0
  41. package/src/implement/composition/pipe.ts +4 -0
  42. package/src/implement/composition/pipe.type-test.ts +17 -1
  43. package/src/implement/composition/sideEffect.ts +1 -1
  44. package/src/implement/object/assocPath.ts +2 -2
  45. package/src/implement/object/dissocPath.ts +2 -2
  46. package/src/implement/object/index.ts +1 -0
  47. package/src/implement/object/path.ts +5 -3
  48. package/src/implement/object/pathKey.ts +1 -0
  49. package/src/implement/object/pathOr.ts +6 -4
  50. package/src/index.ts +3 -0
  51. package/src/stream/index.ts +1 -0
package/README.md CHANGED
@@ -90,7 +90,7 @@ There's no framework and no heavy abstractions—just well-chosen helpers that m
90
90
  `pipe` (sync) and `pipeAsync` (async) are the primary composition tools. All utilities are designed to work seamlessly in pipe chains.
91
91
 
92
92
  - **Pragmatic error handling**
93
- The `SideEffect` pattern handles errors and side effects declaratively in `pipeSideEffect`/`pipeAsyncSideEffect` pipelines. Write normal functions that compose naturally—these pipelines automatically short-circuit when they encounter a `SideEffect`, eliminating the need for wrapper types everywhere. For strict union typing across branches, use `pipeSideEffectStrict` / `pipeAsyncSideEffectStrict`. Use `runPipeResult<T, R>`/`matchSideEffect` **outside** the pipeline with generics for type safety, and `isSideEffect` for runtime type checking.
93
+ The `SideEffect` pattern handles errors and side effects declaratively in `pipeSideEffect`/`pipeAsyncSideEffect` pipelines. Write normal functions that compose naturally—these pipelines automatically short-circuit when they encounter a `SideEffect`, eliminating the need for wrapper types everywhere. For strict union typing across branches, use `pipeSideEffectStrict` / `pipeAsyncSideEffectStrict`. Use `runPipeResult`/`matchSideEffect` **outside** the pipeline. If the result type is widened (e.g. `SideEffect<any>`), provide generics to recover a safe union. Use `isSideEffect` for precise runtime narrowing.
94
94
 
95
95
  - **Immutable & Pure by default**
96
96
  Core utilities avoid mutations and side effects. Any exception is explicitly named (e.g. `tap`, `log`).
@@ -329,7 +329,7 @@ Functions for composing and transforming other functions.
329
329
  - **SideEffect** - Side effect container for SideEffect-aware pipelines
330
330
  - **isSideEffect** - Type guard for runtime checking whether a value is a SideEffect
331
331
  - **matchSideEffect** - Pattern match on value or SideEffect
332
- - **runPipeResult** - Execute SideEffect or return value (call OUTSIDE pipelines). **⚠️ CRITICAL:** `runPipeResult<T, R=any>` has default `R=any`, so using it without generics returns `any` type. Always provide explicit type parameters `runPipeResult<SuccessType, ErrorType>` for type safety. Use `isSideEffect` for runtime type checking
332
+ - **runPipeResult** - Execute SideEffect or return value (call OUTSIDE pipelines). If the input is widened to `SideEffect<any>`/`any`, the result becomes `any`; provide explicit type parameters `runPipeResult<SuccessType, ErrorType>` to recover a safe union. Use `isSideEffect` for precise type narrowing.
333
333
 
334
334
  ### Control Flow
335
335
 
@@ -583,34 +583,35 @@ const processNumbers = pipeSideEffect(
583
583
 
584
584
  const oddsDoubled = processNumbers([1, 2, 3, 4, 5]);
585
585
 
586
- // ✅ CORRECT: Use isSideEffect for type checking + provide generics to runPipeResult
586
+ // ✅ CORRECT: Use isSideEffect for type checking
587
587
  if (!isSideEffect(oddsDoubled)) {
588
588
  // TypeScript knows: oddsDoubled is number[]
589
589
  const sum: number = oddsDoubled.reduce((a, b) => a + b, 0);
590
590
  console.log(`Sum: ${sum}`); // sum: number
591
591
  } else {
592
- // TypeScript knows: oddsDoubled is SideEffect<string>
593
- // But runPipeResult still returns number[] | string (not fully narrowed)
594
- const error = runPipeResult<number[], string>(oddsDoubled);
595
- console.log(`Error: ${error}`); // error: number[] | string
592
+ // pipeSideEffect widens SideEffect to any, so runPipeResult becomes any here
593
+ const error = runPipeResult(oddsDoubled);
594
+ console.log(`Error: ${error}`); // error: any
596
595
  }
597
596
 
598
- // WRONG: runPipeResult without generics
599
- const result = runPipeResult(oddsDoubled); // result: any (no type information!)
597
+ // ⚠️ If the result type is widened, inference is lost
598
+ const widened: number[] | SideEffect<any> = oddsDoubled;
599
+ const unsafeResult = runPipeResult(widened); // result: any
600
600
 
601
- // ✅ CORRECT: Provide generics to runPipeResult
602
- const result = runPipeResult<number[], string>(oddsDoubled); // result: number[] | string (union type - safe but not narrowed)
601
+ // ✅ CORRECT: Provide generics to recover a safe union
602
+ const safeResult = runPipeResult<number[], string>(oddsDoubled); // result: number[] | string (union type - safe but not narrowed)
603
603
  ```
604
604
 
605
605
  **⚠️ CRITICAL: runPipeResult Type Safety**
606
606
 
607
607
  `runPipeResult<T, R=any>` has a default type parameter `R=any`. This means:
608
608
 
609
- - **Without generics**: `const result = runPipeResult(pipeline(data));` returns `any` type (unsafe!)
610
- - **With generics**: `runPipeResult<SuccessType, ErrorType>(result)` returns union type `SuccessType | ErrorType` (type-safe)
611
- - ✅ **With isSideEffect**: Use for runtime checking whether a value is SideEffect
609
+ - **Precise input types**: `T | SideEffect<'E'>` preserves `T | 'E'` without extra annotations.
610
+ - ⚠️ **Widened inputs**: `T | SideEffect<any>` (or `any`) collapses to `any`.
611
+ - ✅ **With generics**: `runPipeResult<SuccessType, ErrorType>(result)` restores a safe union when inference is lost.
612
+ - ✅ **With isSideEffect**: Use for runtime checking and precise narrowing.
612
613
 
613
- **Always provide generics to `runPipeResult`** for type safety. Use `isSideEffect` for runtime type checking.
614
+ Provide generics when inference is lost; prefer `isSideEffect` for precise narrowing.
614
615
 
615
616
  ### Pipe vs PipeAsync
616
617