News for hackers. Stuff that matters.
Re:The power of Result types in Swift by m3kw9 on Sunday June 17, 2018 @06:19PM (#17334649)
This only pushes the responsibility down lower in the stack. Somewhere someone would have to handle a state where we have data and error being nil at the same time.
Re:The power of Result types in Swift by minfduck on Sunday June 17, 2018 @06:47PM (#17334803)
No it doesn't. This article is specifically about how you can use the Swift type system to prevent that from happening. You get a compile time guarantee that the result will either be data or error.
Re:The power of Result types in Swift by m3kw9 on Monday June 18, 2018 @12:34PM (#17339563)
The server can a aboulutly send you data and error as nil, either by error or on purpose. Someone is gonna handle that.
Re:The power of Result types in Swift by solidsnack9000 on Sunday June 17, 2018 @06:52PM (#17334829)
Actually, it puts the responsibility higher in the stack. The first error effectively terminates the computation, so subcomputations can ignore them and the caller can decide what to do with them.

One good thing about this is not having to push down anything to do with logging or reporting into subcomputations.

Re:The power of Result types in Swift by cnowacek on Sunday June 17, 2018 @06:50PM (#17334817)
Not necessarily. The way that the enumerated type is declared, the associated types of the success and failure values are declared to be normal (not optional). This restricts nil from being passed in as the data or the error.