Skip to content

Instantly share code, notes, and snippets.

Created October 28, 2015 23:52
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/75b879c6030da3441a83 to your computer and use it in GitHub Desktop.
Save anonymous/75b879c6030da3441a83 to your computer and use it in GitHub Desktop.
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