I'm trying to grasp the concept behind curry functions. Below is the code:
class MyHelloWorldClass {
func helloWithName(name: String) -> String {
return "hello, \(name)"
}
}
I can create a variable that points to the class’s helloWithName
function:
let helloWithNameFunc = MyHelloWorldClass.helloWithName
// MyHelloWorldClass -> (String) -> String
My new helloWithNameFunc
is of type MyHelloWorldClass -> (String) -> String
, a function
that takes in an instance of my class
and returns
another function
that takes in a string
value and returns a string
value.
So I can actually call my function
like this:
let myHelloWorldClassInstance = MyHelloWorldClass()
helloWithNameFunc(myHelloWorldClassInstance)("Mr. Roboto")
// hello, Mr. Roboto
Credit: I go this code from this site
What is the benefit of using the above curry function? When would there a need to call a function that takes an instance of its class, that takes the subsequent parameter that was passed.