Skip to content

Robust Error Handling & Smarter Result Composition ⚡

Compare
Choose a tag to compare
@caiolandgraf caiolandgraf released this 13 Mar 17:24
· 18 commits to main since this release

🚀 New Additions:

✅ 📌 Introduced Ok and Fail result classes for more structured error handling.
✅ 🛠️ Added a generic IResult interface with methods to handle both success and failure results.
✅ 🌀 Enhanced methods like map, flatMap, mapFails, flip for better chaining and error propagation.
✅ ⚡ New utilities like unwrapOrElse and unwrapOr for handling fallbacks.
✅ 🔄 Expanded the combine utility for combining multiple results with error propagation.

Differences between versions
  • Types:

    • v2.0.0: The Result type defines the generic parameters <V, E>, while Ok and Fail classes are more explicit with defaults (V = never, E = never).
    • v2.1.0: The Result type uses default values (V = unknown, E = unknown) for more flexibility.
  • Method Implementations:

    • v2.0.0: Methods like map, flatMap, unwrapOrElse are more streamlined and return the same type (Ok or Fail) for chaining without much type manipulation.
    • v2.1.0: The mapFails method is more precise in how it deals with failures, clearly transforming errors and allowing for stronger type safety.
  • Combine Utility:

    • v2.0.0: The combine function ensures that errors are aggregated by collecting them from all Fail results and returns a single Fail containing all error values.
    • v2.1.0: The combine function is slightly modified to ensure it handles empty Fail values more effectively and uses the unwrapOr method to extract values in the Ok case.
  • Error Propagation:

    • v2.0.0: Focuses on a simpler structure where the unwrap function throws an error if called on a Fail.
    • v2.1.0: Adds more functionality to handle fallback values (unwrapOr, unwrapOrElse), improving error recovery flexibility.

Made with 💻, ☕, and a bit of 🪄 by @caiolandgraf