File tree Expand file tree Collapse file tree 2 files changed +39
-1
lines changed Expand file tree Collapse file tree 2 files changed +39
-1
lines changed Original file line number Diff line number Diff line change @@ -199,6 +199,25 @@ extension Delta where Element: ~Copyable {
199
199
try coalesce ( source, target)
200
200
}
201
201
}
202
+
203
+ /// Returns whether the delta is of the transition case and a predicate is true given the source and target elements.
204
+ ///
205
+ /// A source delta or target delta always returns `false` without invoking `predicate`.
206
+ ///
207
+ /// - Parameter predicate: The return value of this function is returned by `isIdentity(by:)`.
208
+ @inlinable
209
+ public func isIdentity< E> (
210
+ by predicate: ( _ source: borrowing Element , _ target: borrowing Element ) throws ( E ) -> Bool
211
+ ) throws ( E) -> Bool {
212
+ switch self {
213
+ case . source( _) :
214
+ false
215
+ case . target( _) :
216
+ false
217
+ case . transition( let source, let target) :
218
+ try predicate ( source, target)
219
+ }
220
+ }
202
221
}
203
222
204
223
extension Delta : Copyable where Element: Copyable {
@@ -257,7 +276,24 @@ extension Delta: Copyable where Element: Copyable {
257
276
}
258
277
}
259
278
260
- extension Delta : Equatable where Element: Equatable { }
279
+ extension Delta : Equatable where Element: Equatable {
280
+ /// Returns whether the delta is of the transition case with the source equal to the target.
281
+ ///
282
+ /// Whether this is an identity delta is determined using the equality of `Equatable`, not reference identity (`===`).
283
+ ///
284
+ /// A source delta or target delta always returns `false`.
285
+ @inlinable
286
+ public func isIdentity( ) -> Bool {
287
+ switch self {
288
+ case . source( _) :
289
+ false
290
+ case . target( _) :
291
+ false
292
+ case . transition( let source, let target) :
293
+ source == target
294
+ }
295
+ }
296
+ }
261
297
262
298
extension Delta : Hashable where Element: Hashable { }
263
299
Original file line number Diff line number Diff line change 35
35
### Identity Delta
36
36
37
37
- `` identity(_:) ``
38
+ - `` isIdentity() ``
39
+ - `` isIdentity(by:) ``
You can’t perform that action at this time.
0 commit comments