Avatar
Avatar
Kyome22
@swift-6.0.3 import Foundation 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) (edited)
file:///Users/username (edited)