concept Result type in category swift

This is an excerpt from Manning's book Swift in Depth.
Swift 5 offers an official solution to asynchronous error handling. According to rumor, Swift will offer an even better solution once the async/await pattern gets introduced somewhere around Swift version 7 or 8. The community seems to favor asynchronous error handling with the Result type (which is reinforced by Apple’s inclusion of an official Result type since Swift 5). You may already have worked with the Result type and even implemented it in projects. In this chapter, you’ll use one offered by Swift, which may be a bit more advanced than most examples found online. To get the most out of Result, you’ll go deep into the rabbit hole and look at propagation and so-called monadic error handling. The Result type is an enum like Optional, with some differences, so if you’re comfortable with Optional, then Result should not be too big of a jump.
You’ll start off by exploring the Result type’s benefits and how you can add it to your projects. You’ll create a networking API, and then keep improving it in the following sections. Then you’ll start rewriting the API, but you’ll use the Result type to reap its benefits.
In its simplest form, the Result type looks as follows.
Listing 11.1. The Result type
public enum Result<Success, Failure: Error > { #1 /// Indicates success with value in the associated object. case success(Success) #2 /// Indicates failure with error inside the associated object. case failure(Failure) #3 // ... The rest is left out for later }The difference with Optional is that instead of a value being present (some case) or nil (none case), Result states that it either has a value (success case) or it has an error (failure case). In essence, the Result type indicates possible failure instead of nil. In other words, with Result you can give context for why an operation failed, instead of missing a value.
Unfortunately, the Cocoa Touch way has some problems—which you’ll uncover in a moment—and the Result type solves them. The Result type, inspired by Rust’s Result type and the Either type in Haskell and Scala, is a functional programming idiom that has been taken on by the Swift community.