|
2 | 2 |
|
3 | 3 | * Proposal: [SE-0240](0240-ordered-collection-diffing.md)
|
4 | 4 | * Authors: [Scott Perry](https://github.com/numist), [Kyle Macomber](https://github.com/kylemacomber)
|
5 |
| -* Review Manager: [Doug Gregor](https://github.com/DougGregor) |
| 5 | +* Review Manager: [Doug Gregor](https://github.com/DougGregor), [Ben Cohen](https://github.com/AirspeedSwift) |
6 | 6 | * Status: **Implemented (Swift 5.1)**
|
| 7 | +* Amendment status: **Active Review (June 19 - 25 2019)** |
7 | 8 | * Implementation: [apple/swift#21845](https://github.com/apple/swift/pull/21845)
|
8 | 9 | * Decision notes: [Rationale](https://forums.swift.org/t/accepted-with-modifications-se-0240-ordered-collection-diffing/20008)
|
9 | 10 |
|
@@ -140,6 +141,9 @@ public struct CollectionDifference<ChangeElement> {
|
140 | 141 |
|
141 | 142 | /// The `.remove` changes contained by this difference, from lowest offset to highest
|
142 | 143 | public var removals: [Change] { get }
|
| 144 | + |
| 145 | + /// Produces a difference that is the functional inverse of `self` |
| 146 | + public func inverse() -> CollectionDifference<ChangeElement> |
143 | 147 | }
|
144 | 148 |
|
145 | 149 | /// A CollectionDifference is itself a Collection.
|
@@ -290,26 +294,6 @@ The name `CollectionDifference` gives us the opportunity to build a family of re
|
290 | 294 |
|
291 | 295 | This API allows for more interesting functionality that is not included in this proposal.
|
292 | 296 |
|
293 |
| -For example, this propsal could have included a `inverted()` function on the difference type that would return a new difference that would undo the application of the original. |
294 |
| - |
295 |
| -The lack of additional conveniences and functionality is intentional; the goal of this proposal is to lay the groundwork that such extensions would be built upon. |
296 |
| - |
297 |
| -In the case of `inverted()`, clients of the API in this proposal can use `Collection.map()` to invert the case of each `Change` and feed the result into `CollectionDifference.init(_:)`: |
298 |
| - |
299 |
| -``` swift |
300 |
| -let diff: CollectionDifference<Int> = /* ... */ |
301 |
| -let inverted = CollectionDifference<Int>( |
302 |
| - diff.map({(change) -> CollectionDifference<Int>.Change in |
303 |
| - switch change { |
304 |
| - case .insert(offset: let o, element: let e, associatedWith: let a): |
305 |
| - return .remove(offset: o, element: e, associatedWith: a) |
306 |
| - case .remove(offset: let o, element: let e, associatedWith: let a): |
307 |
| - return .insert(offset: o, element: e, associatedWith: a) |
308 |
| - } |
309 |
| - }) |
310 |
| -)! |
311 |
| -``` |
312 |
| - |
313 | 297 | ### `mutating apply(_:)`
|
314 | 298 |
|
315 | 299 | There is no mutating applicator because there is no algorithmic advantage to in-place application.
|
|
0 commit comments