Created
June 6, 2014 23:48
-
-
Save ayanonagon/fe1e4fb30eacb1352d28 to your computer and use it in GitHub Desktop.
Currying in Swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
💓