Skip to content

Instantly share code, notes, and snippets.

@saiday
Last active January 7, 2020 17:22
Show Gist options
  • Save saiday/8882853369486af49617c2be9cfb6ba8 to your computer and use it in GitHub Desktop.
Save saiday/8882853369486af49617c2be9cfb6ba8 to your computer and use it in GitHub Desktop.
instance method curried function
class C {
func printla(_ msg: String) { print(msg) }
func getPrinter(_ msg: String) -> (String)->() { return { msg in self.printla(msg) } }
}
let c = C()
let im = C.printla // im is of type (C)->(String)->(),
im(c)("who let the dogs out") // prints "who let the dogs out"
let sim = im(c) // sim is of type (String)->()
sim("me") // prints "me"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment