Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement supporting of additional parameters in extension functions #23

Closed
olxmute opened this issue Jan 25, 2021 · 0 comments · Fixed by #24
Closed

Implement supporting of additional parameters in extension functions #23

olxmute opened this issue Jan 25, 2021 · 0 comments · Fixed by #24

Comments

@olxmute
Copy link
Contributor

olxmute commented Jan 25, 2021

Now we can create mapstruct method only with one parameter, that will become receiver in extension function. I think it would be great, if we could create methods with additional parameters. First parameter as receiver of extension function and others as input parameters.

Example:

data class EmployeeModel(val firstName: String)
data class EmployeeCompanyView(val firstName: String, val company: String)

@Mappings(
  Mapping(target = "company", source = "company")
)
abstract fun toEmployeeCompanyView(employeeModel: EmployeeModel, company: String): EmployeeCompanyView

Compiled to:

fun EmployeeModel.toEmployeeCompanyView(company: String) =
    Mappers.getMapper(EmployeeMapper::class.java).toEmployeeCompanyView(this, company)

So we can call:

val model = EmployeeModel("Alex")
val view = model.toEmployeeCompanyView("amazon")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant