Avatar
@swift-5.0.3 enum MyResult<Success, Failure: Error> { case success(Success) case failure(Failure) } extension MyResult where Failure == Error { init(catching body: () throws -> Success) { do { self = .success(try body()) } catch { self = .failure(error) } } } print(type(of: MyResult { 1 }))