Avatar
// Manual propagation struct FooError: Error {} func foo(string: String) -> Result<Int, FooError> { guard let number = Int(string) else { return .failure(FooError()) } return .success(number) } let a: Result<Int, any Error> = .success(2) let b: Result<Int, any Error> = .failure(FooError()) let sum: Result<Int, any Error> = a.flatMap { a in b.map { b in a + b } } print(sum) // Automatic propagation //func foo(string: String) throws -> Int { // let a = try bar() // let b = try baz() // return a + b //} //do { // try inputStream.readLine() // // try inputStream.readLine() // try inputStream.readLine() // try inputStream.readLine() // //} catch { // // エラーハンドリング //} // do { try foo() bar() try baz() } catch { // エラーハンドリング }