Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Swift Chain Function
* chain takes in any number of 1-argument functions as arguments
* and returns a function that executes each function in order
func chain<T>(all: T -> () ...) -> T -> () {
return { x in
for f in all { f(x) }
// Example
var stack: [Int]
chain(stack.append, println)(10)
// is equivalent to
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment