Currying in Swift, new syntax for declarations in the future?

Just install Swift today on Linux to check it out.

Try a small example of the currying result in a warning that the currying syntax will change in the future, however I could not find anything about what this new syntax looks like.

Curry example I tried:

func do_stuff(x: Int) (y: Int) (z: Int) -> Int {
    return (x - y) * z
}
let curry_fun = do_stuff(42)
let x = curry_fun(y: 7)(z: 3)

compiling this example results in the following warning:

warning: curried function declaration syntax will be removed in a future version of Swift; use a single parameter list
func do_stuff(x: Int) (y: Int) (z: Int) -> Int {
             ^~~~~~~~~~~~~~~~~~~~~~~~~~
                    ,        ,

So what does currying look like in the future fast?

I tried something like func do_stuff(x: Int, y: Int, z: Int) -> Int..., however, I could not find a way to do this using this function.

+4
source share
3 answers

only the syntax of the declaration, for example, will be deleted. func(a: Int)(b:Int) -> Int

func curry(a: Int)(b: Int) -> Int {
    return a + b
}

is equivalent to:

func newCurry(a: Int) -> (b: Int) -> Int {
    return { b in
        return a + b
    }
}
+18
source

, .

swift-evolution github repository:

Curried function func foo(x: Int)(y: Int) . .

+2

The syntax for declaring a Curried function has been removed in Swift3, we should use a parameter list instead.

-1
source

Source: https://habr.com/ru/post/1619057/


All Articles