Repository navigation
Robust Error Handling & Smarter Result Composition ⚡
🚀 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
Resulttype defines the generic parameters<V, E>, whileOkandFailclasses are more explicit with defaults (V = never,E = never). - v2.1.0: The
Resulttype uses default values (V = unknown,E = unknown) for more flexibility.
- v2.0.0: The
-
Method Implementations:
- v2.0.0: Methods like
map,flatMap,unwrapOrElseare more streamlined and return the same type (OkorFail) for chaining without much type manipulation. - v2.1.0: The
mapFailsmethod is more precise in how it deals with failures, clearly transforming errors and allowing for stronger type safety.
- v2.0.0: Methods like
-
Combine Utility:
- v2.0.0: The
combinefunction ensures that errors are aggregated by collecting them from allFailresults and returns a singleFailcontaining all error values. - v2.1.0: The
combinefunction is slightly modified to ensure it handles emptyFailvalues more effectively and uses theunwrapOrmethod to extract values in theOkcase.
- v2.0.0: The
-
Error Propagation:
- v2.0.0: Focuses on a simpler structure where the
unwrapfunction throws an error if called on aFail. - v2.1.0: Adds more functionality to handle fallback values (
unwrapOr,unwrapOrElse), improving error recovery flexibility.
- v2.0.0: Focuses on a simpler structure where the
Made with 💻, ☕, and a bit of 🪄 by @caiolandgraf