Avatar
dataTask については、戻り値を URLSessionDataTask に使ってるのが微妙だけど、これは Foundation の API 設計の問題だと思うなぁ。
2:06 AM
response をエラーケースでも受け取りたいとしても、 dataresponseerror を受け取るだけなら↓ async/await と typed throws で↓にできる。 func dataTask(with url: URL) async throws URLSessionDataTaskError -> (Data, URLResponse) { ... } struct URLSessionDataTaskError: Error { let response: URLResponse? }
2:08 AM
以前 Joe Groff が Result 全否定してたときのコメント。 Yeah, we extensively discussed adding a Result type internally, but ultimately couldn't justify it. The only real use case we could see in the wild was for threading errors through CPS-inversion-style abstractions like async promises, something we hope to provide proper language support for. More generally, expressing effects as monadic values is a pretty awful abstraction; aside from polluting the Internet with an endless deluge of unhelpful tutorials, they also don't compose cleanly, they impose nesting where is desired—you have to pick between Result<Async<T>> and Async<Result<T>>, or build ResultT<AsyncT<Identity>><T> out of monad transformers—and they don't do the natural thing when used with other higher-order abstractions—if you're mapping a `throws` function over a collection, you probably want to propagate that error like `rethrows` does, not end up with a collection of Result<T>. I'd rather see us adopt an extensible algebraic effects system, something like http://www.eff-lang.org , which provides a framework for `throws`, `async` and other control flow effects to be cleanly composed and abstracted over. I see `throws` as the first seed of that. https://forums.swift.org/t/throws-as-returning-a-result/1799/2
Yeah, we extensively discussed adding a Result type internally, but ultimately couldn't justify it. The only real use case we could see in the wild was for threading errors through CPS-inversion-style abstractions like async promises, something we hope to provide proper langu...