From cca7c21effd52dcf88632ad20c00c7ace14cc188 Mon Sep 17 00:00:00 2001 From: Javier Cicchelli Date: Thu, 2 Oct 2025 03:28:25 +0200 Subject: [PATCH] Improved the generic interface for the "map(_: )" helper function for the AmiiboLiveClient client in the library target. --- .../Public/Clients/AmiiboLiveClient.swift | 23 ++++++++----------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/Sources/AmiiboService/Public/Clients/AmiiboLiveClient.swift b/Sources/AmiiboService/Public/Clients/AmiiboLiveClient.swift index b8c087a..7a137a0 100644 --- a/Sources/AmiiboService/Public/Clients/AmiiboLiveClient.swift +++ b/Sources/AmiiboService/Public/Clients/AmiiboLiveClient.swift @@ -226,7 +226,7 @@ private extension AmiiboLiveClient { case let .ok(ok): switch ok.body { case let .json(output): - return map(output, as: AmiiboSeries.self) + return map(output) } case .badRequest: throw AmiiboServiceError.badRequest @@ -261,7 +261,7 @@ private extension AmiiboLiveClient { case let .ok(ok): switch ok.body { case let .json(output): - return map(output, as: AmiiboType.self) + return map(output) } case .badRequest: throw AmiiboServiceError.badRequest @@ -296,7 +296,7 @@ private extension AmiiboLiveClient { case let .ok(ok): switch ok.body { case let .json(output): - return map(output, as: GameCharacter.self) + return map(output) } case .badRequest: throw AmiiboServiceError.badRequest @@ -331,7 +331,7 @@ private extension AmiiboLiveClient { case let .ok(ok): switch ok.body { case let .json(output): - return map(output, as: GameSeries.self) + return map(output) } case .badRequest: throw AmiiboServiceError.badRequest @@ -406,29 +406,26 @@ private extension AmiiboLiveClient { ) -> [Amiibo] { switch wrapper.amiibo { case let .Amiibo(object): - return [.init(object)] + return [Amiibo(object)] case let .AmiiboList(list): return list - .map { .init($0) } + .map { Amiibo($0) } .sorted { $0.identifier < $1.identifier } } } /// Retrieves a list of items that conforms to the `KeyNameModel` protocol from a wrapper container. - /// - Parameters: - /// - wrapper: A wrapper container that either has an object or a list of items. - /// - as: a model type that conforms to the `KeyNameModel` protocol. + /// - Parameter wrapper: A wrapper container that either has an object or a list of items. /// - Returns: A list of items that conforms to the `KeyNameModel` protocol, sorted by keys. func map( - _ wrapper: Components.Schemas.TupleWrapper, - as: Model.Type + _ wrapper: Components.Schemas.TupleWrapper ) -> [Model] { switch wrapper.amiibo { case let .Tuple(payload): - return [.init(payload)] + return [Model(payload)] case let .TupleList(list): return list - .map { .init($0) } + .map { Model($0) } .sorted { $0.key < $1.key } } }