Skip to content

v1.2.0

Latest

Choose a tag to compare

@richecr richecr released this 08 Dec 23:45
· 3 commits to main since this release

What's Changed

Added

  • tap helper 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)
    );
  • inspect helper function: Logs values with optional labels for debugging.

    • Specialized version of tap that automatically uses console.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')
    );
  • all combinator for Maybe, Result, and Either: Combines an array of monads into a single monad containing an array of values.

    • Maybe: Returns Just with all values if all are Just, or Nothing if any is Nothing.
    • 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]>
  • sequence combinator for Result and Either: 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!
  • partition function for Result and Either: 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