Proposal: Add withNilReporting Convenience Interface for Optional Unwrapping with Fallback and Error Reporting #164
vladyslavsosiuk
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I’d like to propose a new convenience interface that simplifies optional unwrapping while also reporting a failure when the value is unexpectedly
nil
.✨ Motivation
In many real-world scenarios, we need to unwrap an optional, fall back to a default value if it’s nil, and still report the fact that the value was missing. This is especially important in production environments, where silent fallbacks can mask underlying issues.
This idea is inspired by the existing withErrorReporting pattern, and I believe a similar approach could be applied to optional unwrapping to improve both code clarity and observability.
Proposed API:
✅ Usage Example
Before:
After:
📌 Benefits
Would love to hear your thoughts.
Beta Was this translation helpful? Give feedback.
All reactions