What's Changed
Added
-
taphelper function: Executes side-effects in functional pipelines without altering data flow.- Generic utility that works with any type (monads, primitives, objects, arrays).
- Useful for debugging, logging, metrics, and error tracking.
- Example:
pipe( just(42), tap(x => console.log('Value:', x)), map(x => x * 2) );
-
inspecthelper function: Logs values with optional labels for debugging.- Specialized version of
tapthat automatically usesconsole.log. - Convenient for quick debugging with optional label prefixes.
- Example:
pipe( just(42), inspect('After init'), // Logs: "After init: Just(42)" map(x => x * 2), inspect('Final result') );
- Specialized version of
-
allcombinator forMaybe,Result, andEither: Combines an array of monads into a single monad containing an array of values.Maybe: ReturnsJustwith all values if all areJust, orNothingif any isNothing.Result/Either: Collects all errors if any fail.- Heterogeneous tuple support: Preserves different types in arrays using advanced TypeScript type inference.
- Example:
all([just(1), just(2), just(3)]).unwrapOr([]); // [1, 2, 3] all([ok(1), err('e1'), err('e2')]); // Err(['e1', 'e2']) all([just(42), just("hello"), just(true)]); // Just<[number, string, boolean]>
-
sequencecombinator forResultandEither: Combines an array of monads with fail-fast behavior.- Stops at the first error instead of collecting all errors.
- Returns single error type instead of array.
- Heterogeneous tuple support: Preserves different types in arrays.
- Example:
sequence([ok(1), err('e1'), err('e2')]); // Err('e1') - stops at first!
-
partitionfunction forResultandEither: Separates an array of monads into successes and failures.- Returns a plain object with two arrays (not a monad).
- Always processes all items.
- Heterogeneous tuple support: Preserves different types in returned arrays.
- Example:
partition([ok(1), err('e1'), ok(2), err('e2')]); // { oks: [1, 2], errs: ['e1', 'e2'] }
-
Common Patterns documentation: Added comprehensive documentation section with practical recipes for:
- Validation pipelines with multiple checks
- Form validation with error collection
- Concurrent operations handling
- Async error handling patterns
- Data transformation pipelines