Skip to content

Instantly share code, notes, and snippets.

@DJBen
Created October 7, 2014 20:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DJBen/55e99da8bfce7542b276 to your computer and use it in GitHub Desktop.
Save DJBen/55e99da8bfce7542b276 to your computer and use it in GitHub Desktop.
Swift Currying
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