Improved the generic interface for the "map(_: )" helper function for the AmiiboLiveClient client in the library target.

This commit is contained in:
2025-10-02 03:28:25 +02:00
parent 09dcc9987a
commit cca7c21eff
@@ -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<Model: KeyNameModel>(
_ 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 }
}
}