Comments (6)
I also think a syntax like rethrow()<>
for the specific result types where Err extends Exception reads better.
For cases where result Err is of some other type that does not extend exception, i think it would be difficult to make a more generic version of this function without throwing something, unless perhaps a third state was added to Result, something like Result.ExcludedErr
where invoking things like onSuccess and onFailure on it do nothing.
from kotlin-result.
@grodin separate PRs for each one would be best.
from kotlin-result.
See this comment on the above linked issue for an example of what goes wrong.
from kotlin-result.
The existing signature of runCatching is likely to stay true to whatever the stdlib does, I don't think its wise to deviate from that in terms of user expectations. I do however like the idea proposed here with the except
function. Maybe we could make that work for more than just exceptions too. That also means that in future, the signature of runSuspendCatching
would just be runCatching { it }.except<CancellationException>()
or similar.
from kotlin-result.
That's quite funny: I had exactly the same thought and that's exactly how I implemented runSuspendCatching
in my own project!
I'd suggest a slightly better name for except()
, like rethrow()
or something to make it a bit clearer what it does.
I'm not quite sure what you mean by making that extra function rethrow
or whatever work for things other than exceptions. If the error isn't an exception how do we throw it? Did you have something else in mind?
Do you want separate PRs, firstly for except
/rethrow
and then another for runSuspendCatching
to keep the git history nice or just one PR with unsquashed commits?
from kotlin-result.
I think you might have closed this prematurely. You've merged throwIf
but that leaves runSuspendCatching
still to implement. I've done that actually, and will send a PR as soon as I've rebased and written the kdoc but just in case, maybe this should be reopened.
from kotlin-result.
Related Issues (20)
- Kotlin bugs with value classes HOT 4
- How to use the new inlined Result in non-Kotlin code? HOT 9
- Issues with @JvmStatic code HOT 4
- Detekt rule to detect missing `.bind()` calls inside `suspendBinding` and `binding` HOT 3
- Result 2.0: unsafe unwrapping of `Result.value` and `Result.error` HOT 2
- Provide `mapIfInstance`?
- Assertion helpers for tests HOT 3
- Feature request: mingwX86 target HOT 2
- Extensions for Kotlin Flow? HOT 7
- About component1() and 2 HOT 2
- Best practices for integrating with Flow<T> HOT 1
- ensureNotNull-alike binding scope extensions HOT 15
- e: Could not load module <Error module> HOT 6
- Recovery extension HOT 3
- Consider using consistent "error" naming over "failure"? HOT 2
- Consider adding zipOrAccumulate? HOT 13
- Documentation of order of elements in Iterable.kt HOT 2
- Discuss: Use coroutines instead of exceptions for binding HOT 2
- `orElse` for Error Type Transformation HOT 2
- Make BindException public HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from kotlin-result.