Just installed Swift today in Linux to check it out.
Trying a small example of currying results in a warning that the syntax for currying will change in the future, however I could not find anything about what this new syntax looks like.
The currying 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 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 then look like in future swift?
I did try something like func do_stuff(x: Int, y: Int, z: Int) -> Int...
, however I couldn't find a way to do currying with that function..
As far as I understand they plan to remove it completely.
Here is a quote from the swift-evolution github repository:
Curried function declaration syntax func
foo(x: Int)(y: Int)
is of limited usefulness and creates a lot of language and implementation complexity. We should remove it.
only the declaration syntax will be removed e.g. 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
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With