[swift-users] Generics with variable argument lists

Rien Rien at Balancingrock.nl
Thu Mar 9 04:05:35 CST 2017


I am trying to achieve the following:

enum FunctionResult<T> {
  case success(T)
  case error(String)
}

func tester<T>(test: (…) -> FunctionResult<T>, onError: (String) -> T) -> T {
   …
}

The problem is of course the (…) that simply does not work.

I would like to use this generic with a variety of different signatures, i.e.:

let result1 = tester(test: myfunc1(param: 26) -> FunctionResult<Bool>, onError: { … handle the error ... })
let result2 = tester(test: myfunc2(param: “A String") -> FunctionResult<Bool>, onError: { … handle the error ... })
let result3 = tester(test: myfunc3(param: 26, param2: “String") -> FunctionResult<Int>, onError: { … handle the error ... })

Is this at all possible?

Regards,
Rien

Site: http://balancingrock.nl
Blog: http://swiftrien.blogspot.com
Github: http://github.com/Balancingrock
Project: http://swiftfire.nl







More information about the swift-users mailing list