Slow closing in Swift

In fast, we can define a function like this:

func format(name: String)(email: String) -> String {
       return "\(name)-\(email)"
}

I want to define a closure that looks like this function. But the compiler gives me an error. Here is my curry closure as follows:

let formatClosure = {(name: String)(email: String) -> String in "\(name)-\(email)"}

Is this just not possible in swift or is there some other syntax for it?

+4
source share
1 answer

It seems that the short version available for direct functions does not work for closing. You can still do this using slightly advanced syntax.

let formatClosure = {(name: String) -> String -> String in { email in "\(name)-\(email)" } }
+2
source

All Articles