Merging Closure into Protocols

I quite like this idea and have written my thoughts on this topic down here on a similar thread:

The Function protocol looks very interesting. If we add an associated error type we can support throwing functions as well e.g.:

protocol Function<each Parameters, Error, Result> {
  associatedtype each Parameters
  associatedtype Error 
  associatedtype Result

  func callAsFunction(_: repeat each Parameters) throws(Error) -> Result
}

In addition, we would want to make in ~Escable to make it non-escaping by default and likely ~Copyable or inherit from AnyObject to have reference semantics.

Async functions would likely just need a separate AsyncFunction protocol.

3 Likes