Skip to content

Instantly share code, notes, and snippets.

Embed
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
stack.append(10)
println(10)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.