Skip to content

Instantly share code, notes, and snippets.

Created October 28, 2015 23:52
Embed
What would you like to do?
turn foo.xInPlace(arg) into a foo.x(arg)...
func modifiedCopy<Struct, Arg>(start: Struct, @noescape mutator: (inout Struct) -> Arg -> (), arg: Arg) -> Struct {
var new = start
mutator(&new)(arg)
return new
}
extension Array {
func arrayByAppending(e: Element) -> Array {
return modifiedCopy(self, mutator: Array.append, arg: e)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment