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
Result
type defines the generic parameters<V, E>
, whileOk
andFail
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.
- v2.0.0: The
-
Method Implementations:
- v2.0.0: Methods like
map
,flatMap
,unwrapOrElse
are more streamlined and return the same type (Ok
orFail
) 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.
- v2.0.0: Methods like
-
Combine Utility:
- v2.0.0: The
combine
function ensures that errors are aggregated by collecting them from allFail
results and returns a singleFail
containing all error values. - v2.1.0: The
combine
function is slightly modified to ensure it handles emptyFail
values more effectively and uses theunwrapOr
method to extract values in theOk
case.
- v2.0.0: The
-
Error Propagation:
- v2.0.0: Focuses on a simpler structure where the
unwrap
function 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