Skip to content

Commit 542cea8

Browse files
authored
feat: add mapToContent function to Internal Response (#45)
1 parent 89d2105 commit 542cea8

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

Sources/YData/Client/InternalResponse+Vapor.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ public extension EventLoopFuture where Value: InternalResponse {
1818
func mapContent<NewValue>(_ callback: @escaping (ContentContainer) throws -> (NewValue))
1919
-> EventLoopFuture<Value> where NewValue: Content { flatMapThrowing { try $0.map(callback) } }
2020

21-
func mapToContent<R>() -> EventLoopFuture<R> where R: Decodable {
22-
flatMapThrowing { response -> R in try response.content.decode(R.self) }
21+
func mapToContent<D: Decodable>(_ type: D.Type = D.self) -> EventLoopFuture<D> {
22+
flatMapThrowing { response -> D in try response.content.decode(type) }
2323
}
2424

2525
func flatMapContentThrowing<NewValue>(_ callback: @escaping (ContentContainer) throws -> (NewValue))

Sources/YData/Client/InternalResponse.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ public extension InternalResponse {
2828

2929
return Self.init(headers: headers, status: status, body: nil)
3030
}
31+
32+
@inlinable
33+
func mapToContent<D: Decodable>(_ type: D.Type = D.self) throws -> D {
34+
try content.decode(type)
35+
}
3136
}
3237

3338
public extension Internal {

0 commit comments

Comments
 (0)