You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// `if let source, let target` does not work with non-copyable types here
86
+
self=.modified(source: source!, target: target!)
95
87
}
96
88
elseiflet source {
97
89
self=.deleted(source: source)
@@ -103,33 +95,15 @@ public enum Delta<Element> {
103
95
returnnil
104
96
}
105
97
}
106
-
107
-
/// The source element, if the delta value is not of type `.added`.
108
-
@inlinable@inline(__always)
109
-
publicvarsource:Element?{
110
-
switchself{
111
-
case.deleted(let source): source
112
-
case.added(_):nil
113
-
case.modified(let source, _): source
114
-
}
115
-
}
116
-
117
-
/// The target element, if the delta value is not of type `.deleted`.
118
-
@inlinable@inline(__always)
119
-
publicvartarget:Element?{
120
-
switchself{
121
-
case.deleted(_):nil
122
-
case.added(let target): target
123
-
case.modified(_,let target): target
124
-
}
125
-
}
126
-
98
+
}
99
+
100
+
publicextensionDeltawhere Element:~Copyable {
127
101
/// Returns a delta containing the results of mapping the given closure over the delta’s elements.
128
102
@inlinable
129
-
publicfunc map<T, E>(
130
-
_ transform:(Element)throws(E)->T
103
+
consumingfunc map<T:~Copyable, E>(
104
+
_ transform:(consumingElement)throws(E)->T
131
105
)throws(E)->Delta<T>{
132
-
switchself{
106
+
switchconsume self {
133
107
case.deleted(let source):
134
108
.deleted(source:trytransform(source))
135
109
case.added(let target):
@@ -141,10 +115,10 @@ public enum Delta<Element> {
141
115
142
116
/// Returns a delta containing the results of mapping the given closure over the delta’s elements, or `nil`, if the closure returns `nil` for any element.
143
117
@inlinable
144
-
publicfuncflatMap<T, E>(
145
-
_ transform:(Element)throws(E)->T?
118
+
consumingfunccompactMap<T:~Copyable, E>(
119
+
_ transform:(consumingElement)throws(E)->T?
146
120
)throws(E)->Delta<T>?{
147
-
switchself{
121
+
switchconsume self {
148
122
case.deleted(let source):
149
123
guardlet source =trytransform(source)else{
150
124
returnnil
@@ -157,20 +131,85 @@ public enum Delta<Element> {
157
131
return.added(target: target)
158
132
case.modified(let source,let target):
159
133
guardlet source =trytransform(source),
160
-
let target =trytransform(target)else{
134
+
let target =trytransform(target)else{
161
135
returnnil
162
136
}
163
137
return.modified(source: source, target: target)
164
138
}
165
139
}
166
140
141
+
/// Returns a reduced view of the delta, favoring the given side.
142
+
///
143
+
/// If an element is available on the favored side, it is returned.
144
+
/// Otherwise, the element on the other side is returned.
0 commit comments