[Pitch] Result success and failure accessors

That won't happen, but I wish it would.

public extension Result where Success: ~Copyable {
  @inlinable init(catching body: () async throws(Failure) -> Success) async {
    do { self = .success(try await body()) }
    catch { self = .failure(error) }
  }
}

That doesn't compile. It looks like

(try? MyOtherType(await request().get())) ?? .init()
(try? await request().get()).map(MyOtherType.init) ?? .init()
struct MyOtherType {
  init(_: MyType) { }
  init() { }
}

…which, like many other problems, would be best served with do-catch expressions:

do { MyOtherType(try await request()) }
catch { .init() }
func request() async throws(MyError) -> MyType {
1 Like