Skip to content
This repository has been archived by the owner on Sep 7, 2021. It is now read-only.

Conform Array to CoruvsResponse #13

Closed
jhoogstraat opened this issue Apr 9, 2020 · 0 comments · Fixed by #33
Closed

Conform Array to CoruvsResponse #13

jhoogstraat opened this issue Apr 9, 2020 · 0 comments · Fixed by #33
Labels
enhancement New feature or request

Comments

@jhoogstraat
Copy link
Contributor

Problem
The ResponseModifier currently only works with one instance of a model and thus cannot be used with components that return an array (Instance method 'respond(with:)' requires the types 'Array< Model>' and 'Model' be equivalent).

Solution
Conform Array to CorvusResponse where Array.Element conforms to CorvusResponse:

extension Array: CorvusResponse where Element: CorvusResponse {
    public init(item: [Element.Item]) {
        self = item.map { Element(item: $0) }
    }
}

Usage

Group("users") {
    ReadOne<User>().respond(with: UserResponse.self)
    ReadAll<User>().respond(with: [UserResponse].self)
}
@jhoogstraat jhoogstraat added the enhancement New feature or request label Apr 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant