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 {
171171 self . elements. append ( . init( key: key, value: value) )
172172 }
173173
174- /// Merge another instance of `Metadata` into this one .
174+ /// Add the contents of a `Sequence` of key-value pairs to this `Metadata` instance .
175175 ///
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) )
181179 }
182180
183181 /// Removes all values associated with the given key.
Original file line number Diff line number Diff line change @@ -268,7 +268,7 @@ struct MetadataTests {
268268 @Test ( " Where key is already present with a different value " )
269269 mutating func mergeWhereKeyIsAlreadyPresentWithDifferentValue( ) async throws {
270270 self . otherMetadata. addString ( " value1-2 " , forKey: " key1 " )
271- self . metadata. merge ( self . otherMetadata)
271+ self . metadata. add ( contentsOf : self . otherMetadata)
272272
273273 #expect( self . metadata == [
274274 " key1 " : " value1-1 " ,
@@ -283,7 +283,7 @@ struct MetadataTests {
283283 @Test ( " Where key is already present with same value " )
284284 mutating func mergeWhereKeyIsAlreadyPresentWithSameValue( ) async throws {
285285 self . otherMetadata. addString ( " value1-1 " , forKey: " key1 " )
286- self . metadata. merge ( self . otherMetadata)
286+ self . metadata. add ( contentsOf : self . otherMetadata)
287287
288288 #expect( self . metadata == [
289289 " key1 " : " value1-1 " ,
@@ -297,7 +297,7 @@ struct MetadataTests {
297297
298298 @Test ( " Where key is not already present " )
299299 mutating func mergeWhereKeyIsNotAlreadyPresent( ) async throws {
300- self . metadata. merge ( self . otherMetadata)
300+ self . metadata. add ( contentsOf : self . otherMetadata)
301301
302302 #expect( self . metadata == [
303303 " key1 " : " value1-1 " ,
You can’t perform that action at this time.
0 commit comments