@@ -123,7 +123,6 @@ public static ValueTask RemoveAllAsync<T>(this IListState<T> state, Predicate<T>
123
123
=> state . UpdateDataAsync ( itemsOpt => itemsOpt . Map ( items => items . RemoveAll ( match ) ) , ct ) ;
124
124
125
125
126
-
127
126
/// <summary>
128
127
/// Updates all items from a list state that match the key of <paramref name="oldItem"/>.
129
128
/// </summary>
@@ -133,7 +132,8 @@ public static ValueTask RemoveAllAsync<T>(this IListState<T> state, Predicate<T>
133
132
/// <param name="newItem">The new value for the item.</param>
134
133
/// <param name="ct">A token to abort the async add operation.</param>
135
134
/// <returns></returns>
136
- public static ValueTask UpdateItemAsync < T > ( this IListState < T > state , T oldItem , T newItem , CancellationToken ct = default ) where T : IKeyEquatable < T >
135
+ public static ValueTask UpdateItemAsync < T > ( this IListState < T > state , T oldItem , T newItem , CancellationToken ct = default )
136
+ where T : notnull , IKeyEquatable < T >
137
137
=> state . UpdateDataAsync (
138
138
itemsOpt => itemsOpt . Map ( items =>
139
139
{
@@ -150,6 +150,33 @@ public static ValueTask UpdateItemAsync<T>(this IListState<T> state, T oldItem,
150
150
ct ) ;
151
151
152
152
153
+ /// <summary>
154
+ /// Updates all items from a list state that match the key of <paramref name="oldItem"/>.
155
+ /// </summary>
156
+ /// <typeparam name="T">The type of the items in the list.</typeparam>
157
+ /// <param name="state">The list state onto which the item should be added.</param>
158
+ /// <param name="oldItem">The old value of the item.</param>
159
+ /// <param name="newItem">The new value for the item.</param>
160
+ /// <param name="ct">A token to abort the async add operation.</param>
161
+ /// <returns></returns>
162
+ public static ValueTask UpdateItemAsync < T > ( this IListState < T ? > state , T oldItem , T ? newItem , CancellationToken ct = default )
163
+ where T : struct , IKeyEquatable < T >
164
+ => state . UpdateDataAsync (
165
+ itemsOpt => itemsOpt . Map ( items =>
166
+ {
167
+ var updated = items ;
168
+ foreach ( var item in items )
169
+ {
170
+ if ( item ? . KeyEquals ( oldItem ) == true )
171
+ {
172
+ updated = items . Replace ( item , newItem ) ;
173
+ }
174
+ }
175
+ return updated ;
176
+ } ) ,
177
+ ct ) ;
178
+
179
+
153
180
/// <summary>
154
181
/// Updates all items from a list state that match the key of <paramref name="oldItem"/>.
155
182
/// </summary>
@@ -159,7 +186,8 @@ public static ValueTask UpdateItemAsync<T>(this IListState<T> state, T oldItem,
159
186
/// <param name="updater">How to update items.</param>
160
187
/// <param name="ct">A token to abort the async add operation.</param>
161
188
/// <returns></returns>
162
- public static ValueTask UpdateItemAsync < T > ( this IListState < T > state , T oldItem , Func < T , T > updater , CancellationToken ct = default ) where T : IKeyEquatable < T >
189
+ public static ValueTask UpdateItemAsync < T > ( this IListState < T > state , T oldItem , Func < T , T > updater , CancellationToken ct = default )
190
+ where T : notnull , IKeyEquatable < T >
163
191
=> state . UpdateDataAsync (
164
192
itemsOpt => itemsOpt . Map ( items =>
165
193
{
@@ -175,6 +203,32 @@ public static ValueTask UpdateItemAsync<T>(this IListState<T> state, T oldItem,
175
203
} ) ,
176
204
ct ) ;
177
205
206
+ /// <summary>
207
+ /// Updates all items from a list state that match the key of <paramref name="oldItem"/>.
208
+ /// </summary>
209
+ /// <typeparam name="T">The type of the items in the list.</typeparam>
210
+ /// <param name="state">The list state onto which the item should be added.</param>
211
+ /// <param name="oldItem">The old value of the item.</param>
212
+ /// <param name="updater">How to update items.</param>
213
+ /// <param name="ct">A token to abort the async add operation.</param>
214
+ /// <returns></returns>
215
+ public static ValueTask UpdateItemAsync < T > ( this IListState < T ? > state , T oldItem , Func < T ? , T ? > updater , CancellationToken ct = default )
216
+ where T : struct , IKeyEquatable < T >
217
+ => state . UpdateDataAsync (
218
+ itemsOpt => itemsOpt . Map ( items =>
219
+ {
220
+ var updated = items ;
221
+ foreach ( var item in items )
222
+ {
223
+ if ( item ? . KeyEquals ( oldItem ) == true )
224
+ {
225
+ updated = items . Replace ( item , updater ( item ) ) ;
226
+ }
227
+ }
228
+ return updated ;
229
+ } ) ,
230
+ ct ) ;
231
+
178
232
179
233
/// <summary>
180
234
/// Updates all matching items from a list state.
0 commit comments