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.
- package/README.md +16 -15
- package/dist/fp-pack.umd.js.map +1 -1
- package/dist/implement/composition/curry.d.ts +5 -5
- package/dist/implement/composition/curry.d.ts.map +1 -1
- package/dist/implement/composition/curry.mjs.map +1 -1
- package/dist/implement/composition/index.d.ts +3 -0
- package/dist/implement/composition/index.d.ts.map +1 -1
- package/dist/implement/composition/pipe.d.ts +3 -0
- package/dist/implement/composition/pipe.d.ts.map +1 -1
- package/dist/implement/composition/pipe.mjs.map +1 -1
- package/dist/implement/composition/pipe.type-test.d.ts +7 -1
- package/dist/implement/composition/pipe.type-test.d.ts.map +1 -1
- package/dist/implement/composition/sideEffect.d.ts +1 -1
- package/dist/implement/composition/sideEffect.d.ts.map +1 -1
- package/dist/implement/composition/sideEffect.mjs.map +1 -1
- package/dist/implement/object/assocPath.d.ts +2 -1
- package/dist/implement/object/assocPath.d.ts.map +1 -1
- package/dist/implement/object/assocPath.mjs.map +1 -1
- package/dist/implement/object/dissocPath.d.ts +2 -1
- package/dist/implement/object/dissocPath.d.ts.map +1 -1
- package/dist/implement/object/dissocPath.mjs.map +1 -1
- package/dist/implement/object/index.d.ts +1 -0
- package/dist/implement/object/index.d.ts.map +1 -1
- package/dist/implement/object/path.d.ts +4 -2
- package/dist/implement/object/path.d.ts.map +1 -1
- package/dist/implement/object/path.mjs.map +1 -1
- package/dist/implement/object/pathKey.d.ts +2 -0
- package/dist/implement/object/pathKey.d.ts.map +1 -0
- package/dist/implement/object/pathOr.d.ts +5 -3
- package/dist/implement/object/pathOr.d.ts.map +1 -1
- package/dist/implement/object/pathOr.mjs.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/skills/fp-pack/SKILL.md +18 -16
- package/dist/skills/fp-pack.md +18 -16
- package/dist/stream/index.d.ts +1 -0
- package/dist/stream/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/implement/composition/curry.ts +5 -5
- package/src/implement/composition/index.ts +3 -0
- package/src/implement/composition/pipe.ts +4 -0
- package/src/implement/composition/pipe.type-test.ts +17 -1
- package/src/implement/composition/sideEffect.ts +1 -1
- package/src/implement/object/assocPath.ts +2 -2
- package/src/implement/object/dissocPath.ts +2 -2
- package/src/implement/object/index.ts +1 -0
- package/src/implement/object/path.ts +5 -3
- package/src/implement/object/pathKey.ts +1 -0
- package/src/implement/object/pathOr.ts +6 -4
- package/src/index.ts +3 -0
- 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
|
|
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).
|
|
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
|
|
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
|
-
//
|
|
593
|
-
|
|
594
|
-
|
|
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
|
-
//
|
|
599
|
-
const
|
|
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
|
|
602
|
-
const
|
|
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
|
-
-
|
|
610
|
-
-
|
|
611
|
-
- ✅ **With
|
|
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
|
-
|
|
614
|
+
Provide generics when inference is lost; prefer `isSideEffect` for precise narrowing.
|
|
614
615
|
|
|
615
616
|
### Pipe vs PipeAsync
|
|
616
617
|
|