Created
January 14, 2015 10:04
-
-
Save sjoerdvisscher/0a8a9c709096868e09a0 to your computer and use it in GitHub Desktop.
zipper-like mutation in Swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| struct Rect { | |
| var width = 1 | |
| var height = 1 | |
| mutating func scaleBy(value: Int) { | |
| width *= value | |
| height *= value | |
| } | |
| } | |
| var rects: [Rect] = [Rect(width: 5,height: 6), Rect(width: 2, height: 3)] | |
| let rect = rects[1] | |
| rects[1].scaleBy(3) | |
| rects // [Rect(5, 6), Rect(6, 9)] | |
| rect // still Rect(2, 3) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment