Skip to content

Instantly share code, notes, and snippets.

@hallski
Last active August 29, 2015 14:02
Show Gist options
  • Save hallski/7733cf0c68b82fcf20a1 to your computer and use it in GitHub Desktop.
Save hallski/7733cf0c68b82fcf20a1 to your computer and use it in GitHub Desktop.
Simple implementation of a partial function in Swift
func partial<T, S, A>(f: ((T, S) -> A), t : T) -> (S -> A) {
return { (s:S) in
return f(t, s)
}
}
// Bind the first argument
let addTwenty = partial(+, 20)
// Call the new function
addTwenty(10)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment