3 ms·
> That swift code is painful to read. I you mean the Swift code in the article, that almost looks like Kotlin :-) Swift requires type constraints on the origi
by Someone 3y ago
> That swift code is painful to read.
I you mean the Swift code in the article, that almost looks like Kotlin :-)
Swift requires type constraints on the original add function, but infers them for addFive.
func add<T> (x:T, y:T) -> T where T: Numeric {
x + y
}
let addFive = {(y) in add(x: 5, y: y)}
let result = addFive(3)
Edit: in Swift 3, one could write
func add<T>(x:T)(y:T) -> T where T: Numeric {
return x + y
}
and call that as
add(x: 2)(y: 3)
or, in two steps, as
let addTwo = add(2)
addTwo(3)
That functionality was removed, though. For reasoning behind that, see https://github.com/apple/swift-evolution/blob/main/proposals/0002-remove-currying.md https://github.com/apple/swift-evolution/blob/main/proposals....
- weatherlight 3y agoI meant Kotlin, i totally whiffed. (can you tell i don't write Swift or Kotlin?) :) (Swift for currying, based on your example, isn't terrible actually!)