Skip to content

Commit b28d38f

Browse files
authored
Removed combineWithKeys, combine assumes keyed containers (#1)
1 parent c6dbb25 commit b28d38f

File tree

2 files changed

+8
-72
lines changed

2 files changed

+8
-72
lines changed

Sources/Coding/Encoding.swift

-10
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,6 @@ public extension Encoding {
2020
///
2121
static func combine(_ encodings: Self...) -> Self {
2222
.init { value, encoder in
23-
var container = encoder.unkeyedContainer()
24-
for encoding in encodings {
25-
try encoding.encode(value, container.superEncoder())
26-
}
27-
}
28-
}
29-
30-
static func combineWithKeys<Key: CodingKey>(_ keyType: Key.Type, _ encodings: Self...) -> Self {
31-
.init { value, encoder in
32-
_ = encoder.container(keyedBy: keyType)
3323
for encoding in encodings {
3424
try encoding.encode(value, encoder)
3525
}

Tests/CodingTests/EncodingTests.swift

+8-62
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,7 @@ final class EncodingTests: XCTestCase {
6161
stringValue(
6262
try encoder.encode(
6363
Value(a: 123, b: nil),
64-
as: .combineWithKeys(
65-
Value.CodingKeys.self,
66-
64+
as: .combine(
6765
Encoding<Int>
6866
.withKey(Value.CodingKeys.a)
6967
.pullback(\.a),
@@ -94,9 +92,7 @@ final class EncodingTests: XCTestCase {
9492
stringValue(
9593
try encoder.encode(
9694
Value(a: 123, b: nil),
97-
as: .combineWithKeys(
98-
Value.CodingKeys.self,
99-
95+
as: .combine(
10096
Encoding<Int>
10197
.withKey(Value.CodingKeys.a)
10298
.pullback(\.a),
@@ -484,56 +480,6 @@ final class EncodingTests: XCTestCase {
484480
)
485481
}
486482

487-
func testUnkeyedEncodingOfValueAttributes() {
488-
struct Value {
489-
var a: Int
490-
var b: String
491-
var c: Bool
492-
}
493-
494-
let value = Value(a: 1, b: "A", c: true)
495-
496-
let encoding: Encoding<Value> = .combine(
497-
Encoding<Int>.singleValue.pullback(\.a),
498-
Encoding<String>.singleValue.pullback(\.b),
499-
Encoding<Bool>.singleValue.pullback(\.c)
500-
)
501-
502-
XCTAssertEqual(
503-
"""
504-
[1,"A",true]
505-
""",
506-
stringValue(try encoder.encode(value, as: encoding))
507-
)
508-
}
509-
510-
func testEncodingOfValueAttributesAsArrayOfIndividualObjects() {
511-
struct Value {
512-
var a: Int
513-
var b: String
514-
var c: Bool
515-
}
516-
517-
enum ValueKeys: CodingKey {
518-
case a, b, c
519-
}
520-
521-
let value = Value(a: 1, b: "A", c: true)
522-
523-
let encoding: Encoding<Value> = .combine(
524-
Encoding<Int>.withKey(ValueKeys.a).pullback(\.a),
525-
Encoding<String>.withKey(ValueKeys.b).pullback(\.b),
526-
Encoding<Bool>.withKey(ValueKeys.c).pullback(\.c)
527-
)
528-
529-
XCTAssertEqual(
530-
"""
531-
[{"a":1},{"b":"A"},{"c":true}]
532-
""",
533-
stringValue(try encoder.encode(value, as: encoding))
534-
)
535-
}
536-
537483
// MARK: - Encoding Property Wrapper
538484

539485
func testEncodingPropertyWrapper() {
@@ -627,8 +573,8 @@ extension Encoding where Value == Manufacturer {
627573
.withKey(Model.CodingKeys.name)
628574
.pullback(\.name)
629575

630-
static let `default`: Self = .combineWithKeys(
631-
Manufacturer.CodingKeys.self,
576+
static let `default`: Self = .combine(
577+
632578
name
633579
)
634580
}
@@ -642,8 +588,8 @@ extension Encoding where Value == Model {
642588
.withKey(Model.CodingKeys.engineSizes)
643589
.pullback(\.engineSizes)
644590

645-
static let `default`: Self = .combineWithKeys(
646-
Model.CodingKeys.self,
591+
static let `default`: Self = .combine(
592+
// Model.CodingKeys.self,
647593
name,
648594
engineSizes
649595
)
@@ -669,8 +615,8 @@ extension Encoding where Value == Car {
669615
.withKey(Car.CodingKeys.availableColors)
670616
.pullback(\.availableColors)
671617

672-
static let `default`: Self = .combineWithKeys(
673-
Car.CodingKeys.self,
618+
static let `default`: Self = .combine(
619+
// Car.CodingKeys.self,
674620
name,
675621
model,
676622
manufacturer,

0 commit comments

Comments
 (0)