Was trying to make a simple example, bad choice. Here is a real world example without any generics - I keep think I should be able to make it some or mostly generic:
typealias XClosure = ((NSArray?) -> Void)
typealias YClosure = ((Any?, Error?) -> Void)
struct Str {
func callAsFunction(val: @escaping XClosure) -> XClosure {
return wrapper(val)
}
func callAsFunction(val: @escaping YClosure) -> YClosure {
return wrapper(val)
}
private func wrapper(_ originalHandler: @escaping XClosure) -> XClosure {
let newHandler: XClosure = { a in
DispatchQueue.main.async {
originalHandler(a)
}
}
return newHandler
}
private func wrapper(_ originalHandler: @escaping YClosure) -> YClosure {
let newHandler: YClosure = { a, b in
DispatchQueue.main.async {
originalHandler(a, b)
}
}
return newHandler
}
}