Skip to content

Commit 2be4be7

Browse files
committed
Rename to add(contentsOf:)
1 parent 94b4643 commit 2be4be7

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

Sources/GRPCCore/Metadata.swift

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff 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.

Tests/GRPCCoreTests/MetadataTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff 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",

0 commit comments

Comments
 (0)