Skip to content

Instantly share code, notes, and snippets.

@natecook1000
Forked from anonymous/modifiedCopy.swift
Last active October 29, 2015 19:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save natecook1000/c3ebce76c81f5254b3d6 to your computer and use it in GitHub Desktop.
Save natecook1000/c3ebce76c81f5254b3d6 to your computer and use it in GitHub Desktop.
turn foo.xInPlace(arg) into a foo.x(arg)...
func modifiedCopy<Struct, Arg>(var start: Struct, @noescape mutator: (inout Struct) -> Arg -> (), arg: Arg) -> Struct {
mutator(&start)(arg)
return start
}
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