I have two data model classes and I want to use a generic extension function to map these classes and other classes.
This is a sample of my code to map the two classes:
fun HomeRequestBodyWithAuthQuery.Client.graphToDomain(): Client =
Client(id = this.id, givenName = this.givenName)
I wrote this extension function but the return value has an error:
fun <G, T> G.graphqlToDomain(): T = T
how can I write a kotlin extension function for this work?
CodePudding user response:
You can take your generic type as a parameter and return it.
fun <G, T> G.graphqlToDomain(t: T): T = t