File tree Expand file tree Collapse file tree 2 files changed +7
-9
lines changed Expand file tree Collapse file tree 2 files changed +7
-9
lines changed Original file line number Diff line number Diff line change @@ -171,13 +171,11 @@ public struct Metadata: Sendable, Hashable {
171
171
self . elements. append ( . init( key: key, value: value) )
172
172
}
173
173
174
- /// Merge another instance of `Metadata` into this one .
174
+ /// Add the contents of a `Sequence` of key-value pairs to this `Metadata` instance .
175
175
///
176
- /// - Parameter other: the `Metadata` which key-value pairs should be merged into this one.
177
- public mutating func merge( _ other: Metadata ) {
178
- for (key, value) in other {
179
- self . addValue ( value, forKey: key)
180
- }
176
+ /// - Parameter other: the `Sequence` whose key-value pairs should be added into this `Metadata` instance.
177
+ public mutating func add( contentsOf other: some Sequence < Element > ) {
178
+ self . elements. append ( contentsOf: other. map ( KeyValuePair . init) )
181
179
}
182
180
183
181
/// Removes all values associated with the given key.
Original file line number Diff line number Diff line change @@ -268,7 +268,7 @@ struct MetadataTests {
268
268
@Test ( " Where key is already present with a different value " )
269
269
mutating func mergeWhereKeyIsAlreadyPresentWithDifferentValue( ) async throws {
270
270
self . otherMetadata. addString ( " value1-2 " , forKey: " key1 " )
271
- self . metadata. merge ( self . otherMetadata)
271
+ self . metadata. add ( contentsOf : self . otherMetadata)
272
272
273
273
#expect( self . metadata == [
274
274
" key1 " : " value1-1 " ,
@@ -283,7 +283,7 @@ struct MetadataTests {
283
283
@Test ( " Where key is already present with same value " )
284
284
mutating func mergeWhereKeyIsAlreadyPresentWithSameValue( ) async throws {
285
285
self . otherMetadata. addString ( " value1-1 " , forKey: " key1 " )
286
- self . metadata. merge ( self . otherMetadata)
286
+ self . metadata. add ( contentsOf : self . otherMetadata)
287
287
288
288
#expect( self . metadata == [
289
289
" key1 " : " value1-1 " ,
@@ -297,7 +297,7 @@ struct MetadataTests {
297
297
298
298
@Test ( " Where key is not already present " )
299
299
mutating func mergeWhereKeyIsNotAlreadyPresent( ) async throws {
300
- self . metadata. merge ( self . otherMetadata)
300
+ self . metadata. add ( contentsOf : self . otherMetadata)
301
301
302
302
#expect( self . metadata == [
303
303
" key1 " : " value1-1 " ,
You can’t perform that action at this time.
0 commit comments