Giter VIP home page Giter VIP logo

Comments (10)

robrix avatar robrix commented on June 3, 2024

Possibly Result<ErrorType, …>?

from result.

yoavschwartz avatar yoavschwartz commented on June 3, 2024

You get an "Expected type" error.
I am not sure how important it is to decide the error type on declaration instead of just having an failure(ErrorType).

from result.

robrix avatar robrix commented on June 3, 2024

Got my parameters the wrong way around. If your operations produce strings, then:

typealias OperationResult = Result<String, ErrorType>

would work, except:

boom.swift:16:29: error: using 'ErrorType' as a concrete type conforming to protocol 'ErrorType' is not supported
typealias OperationResult = Result<String, ErrorType>
                            ^

Maybe we should stop constraining Result’s Error type parameter to ErrorType?

from result.

yoavschwartz avatar yoavschwartz commented on June 3, 2024

Hmmm, in my own private implementation I had something in the lines of:

Result<T>
case Success<T>
case Error <ErrorType>

So this one essentially does the same but you don't have to commit to a specific concrete ErrorType. I think it's more swift-y to say put whatever you want as long as it conforms to ErrorType.

Then you would declare an Result<type> and it's obvious in my opinion that the result also has an error. You don't initialize an optional saying Optional<type,nil> cause its obvious

from result.

neilpa avatar neilpa commented on June 3, 2024

Maybe we should stop constraining Result’s Error type parameter to ErrorType?

This would break all of the throws methods defined in Result.

So this one essentially does the same but you don't have to commit to a specific concrete ErrorType. I think it's more swift-y to say put whatever you want as long as it conforms to ErrorType.

This defeats one of the main benefits of Result which is compile-time error checking

from result.

robrix avatar robrix commented on June 3, 2024

This would break all of the throws methods defined in Result.

Ah, of course.

So this one essentially does the same but you don't have to commit to a specific concrete ErrorType. I think it's more swift-y to say put whatever you want as long as it conforms to ErrorType.

This defeats one of the main benefits of Result which is compile-time error checking

Agreed. I want Swift to declare concrete error types, not to elide them from Result.

from result.

yoavschwartz avatar yoavschwartz commented on June 3, 2024

This defeats one of the main benefits of Result which is compile-time error checking

What advantages do you get from have the type Result<type, NSError> as oppose to Result<type, ErrorType> ?

Agreed. I want Swift to declare concrete error types, not to elide them from Result.

Swift's design already made the choice of not declaring concrete error type in the throws and in fact when you use throws in the Result you lose that information. Otherwise you would write foo() throws CBError or something in the sorts. In all honesty the fact that you have to choose a concrete type at definition is probably a swift error. There is no reason you shouldn't be able to repass ErrorType as a type for your error.

from result.

Thomvis avatar Thomvis commented on June 3, 2024

@yoavschwartz you could create your own enum and then make it conform to ResultType. That will give you most functionality of Result (e.g. map, flatMap) just by implementing a few basic methods on your own type. It might not be a complete solution (we could make it more compelling by moving more functionality from Result to ResultType), but perhaps an interesting one to try out.

from result.

yoavschwartz avatar yoavschwartz commented on June 3, 2024

@Thomvis It's actually what I am already doing ;) I just thought the Result type itself makes more sense when defined by one type and wanted to discuss the pro's and con's like we did here. I am satisfied that there are compelling arguments for both types and you have done great work with the code you wrote. It comes down to design choices. I tried to come up with a way to support both types but you can't overload an Enum.

from result.

robrix avatar robrix commented on June 3, 2024

With that, I’m going to close this out, as there doesn’t seem to be any action to be taken. Thanks for an interesting discussion, all!

from 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.