Created
October 7, 2014 20:32
-
-
Save DJBen/55e99da8bfce7542b276 to your computer and use it in GitHub Desktop.
Swift Currying
This file contains hidden or 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 curry<T, U, V>(value: T, body: (T, U) -> V) -> U -> V { | |
let curried: U -> V = { | |
b in | |
return body(value, b) | |
} | |
return curried | |
} | |
// Examples | |
func add(a: Int, b: Int) -> Int { | |
return a + b | |
} | |
let c = curry(3, add) | |
println("\(c(5))") // 8 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment