Skip to content

Instantly share code, notes, and snippets.

@ayanonagon
Created June 6, 2014 23:48
Show Gist options
  • Save ayanonagon/fe1e4fb30eacb1352d28 to your computer and use it in GitHub Desktop.
Save ayanonagon/fe1e4fb30eacb1352d28 to your computer and use it in GitHub Desktop.
Currying in Swift
func twoWords(a: String) (b: String) -> String {
return "\(a) \(b)"
}
twoWords("Hello")(b: "Ayaka") // Note that you need to explicitly name your second parameter
// Now for currying...
let greet = twoWords("Hello")
greet(b: "Ayaka")
greet(b: "World")
func threeWords(a: String) (b: String) (c: String) -> String {
return "\(a) \(b) \(c)"
}
threeWords("Hello")(b:"World")(c:"!")
let helloWorld = threeWords("Hello")(b: "World")
helloWorld(c: "!")
// Download the playground and try it!
@vprtwn
Copy link

vprtwn commented Jun 7, 2014

💓

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment