Avatar
Avatar
Kyome22
@swift-6.0.3 extension Array { func reduce<Result>( from initialResult: (Element) throws -> Result, successor updateAccumulatingResult: (inout Result, Element) throws -> () ) rethrows -> Result { var array = self let initialResult = try initialResult(array.removeFirst()) return try array.reduce(into: initialResult) { try updateAccumulatingResult(&$0, $1) } } } let url = ["/", "Users", "username"].reduce { URL(filePath: $0) } successor: { $0.append(path: $1) } print(url.absoluteString)
exit status: 1 with <stdin>:15:5: error: cannot find 'URL' in scope 13 | 14 | let url = ["/", "Users", "username"].reduce { 15 | URL(filePath: $0) | `- error: cannot find 'URL' in scope 16 | } successor: { 17 | $0.append(path: $1) <stdin>:16:14: error: cannot infer type of closure parameter '$0' without a type annotation 14 | let url = ["/", "Users", "username"].reduce { 15 | URL(filePath: $0) 16 | } successor: { | `- error: cannot infer type of closure parameter '$0' without a type annotation 17 | $0.append(path: $1) 18 | }