Avatar
norio_nomura 9/12/2018 5:09 AM
zip()のパラメータ、a,b,tどれか一つだけ@escapingが無くても良い。 @swift-4.1.3 @swift-4.2.4 func zip<A,B,T>( _ a: @escaping ((A) throws -> T) throws -> T, _ b: @escaping ((B) throws -> T) throws -> T, _ t: @escaping (A, B) throws -> T ) rethrows -> T { return try a() { _a in return try b() { _b in return try t(_a, _b) } } } let xs = ["x", "s"] let ys = ["y", "s"] let totalByteCount = try zip(xs.withUnsafeBytes, ys.withUnsafeBytes) { x, y in x.count + y.count } print(totalByteCount) // "64\n" (edited)