Coder Social home page Coder Social logo

Comments (6)

robrix avatar robrix commented on August 20, 2024

The static Result.success and Result.failure functions should be usable anywhere success/failure were, while also allowing you to explicitly specify the type (without resorting to as or a temporary variable) should the need arise.

from result.

robrix avatar robrix commented on August 20, 2024

Going to close this out for now, but feel free to reopen if there’s cases that the static functions don’t handle.

from result.

neilpa avatar neilpa commented on August 20, 2024

The static functions are fine, mostly I was looking to save a few characters. Plus I hadn't even considered this which is nice

while also allowing you to explicitly specify the type (without resorting to as or a temporary variable) should the need arise

from result.

robrix avatar robrix commented on August 20, 2024

Note that you can also write .success(…)/.failure(…) anywhere that Swift can infer the return type:

func yep() -> Result<String, String> {
    return .success("👍")
}
let nope: Result<String, String> = .failure("👎")

from result.

neilpa avatar neilpa commented on August 20, 2024

Whoa, I thought that syntax was just for enum cases. It makes sense when I think about it though. They're both static properties/methods that need to be bound to a type.

from result.

robrix avatar robrix commented on August 20, 2024

Yep. Caveat lector: there are some corner cases where they can make compilation slow down unreasonably. I use the notation quite heavily myself, tho.

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.