Skip to content

Commit

Permalink
feat: add mapToContent function to Internal Response (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
tallnato authored Jul 10, 2023
1 parent 89d2105 commit 542cea8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Sources/YData/Client/InternalResponse+Vapor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ public extension EventLoopFuture where Value: InternalResponse {
func mapContent<NewValue>(_ callback: @escaping (ContentContainer) throws -> (NewValue))
-> EventLoopFuture<Value> where NewValue: Content { flatMapThrowing { try $0.map(callback) } }

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

func flatMapContentThrowing<NewValue>(_ callback: @escaping (ContentContainer) throws -> (NewValue))
Expand Down
5 changes: 5 additions & 0 deletions Sources/YData/Client/InternalResponse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ public extension InternalResponse {

return Self.init(headers: headers, status: status, body: nil)
}

@inlinable
func mapToContent<D: Decodable>(_ type: D.Type = D.self) throws -> D {
try content.decode(type)
}
}

public extension Internal {
Expand Down

0 comments on commit 542cea8

Please sign in to comment.