Coder Social home page Coder Social logo

Comments (6)

Munzey avatar Munzey commented on August 15, 2024 2

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.

michaelbull avatar michaelbull commented on August 15, 2024 1

@grodin separate PRs for each one would be best.

from kotlin-result.

grodin avatar grodin commented on August 15, 2024

See this comment on the above linked issue for an example of what goes wrong.

from kotlin-result.

michaelbull avatar michaelbull commented on August 15, 2024

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.

grodin avatar grodin commented on August 15, 2024

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.

grodin avatar grodin commented on August 15, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.