I am just wondering what is the benefit of using the operator invoke than not using it. I am trying it out on one of my interfaces to see what the benefits are.
fun interface MapperDomainToData<in E, out M> {
operator fun invoke(entity: E): M
}
fun interface MapperDomainToData<in E, out M> {
fun map(entity: E): M
}
In my implementation there seems to be no difference. In fact I prefer not using it as the method name is more meaningful.
class MapSocialLoginRequestImp @Inject constructor() : MapperDomainToData<SocialLoginRequestEntity, SocialLoginRequestModel> {
override fun invoke(entity: SocialLoginRequestEntity): SocialLoginRequestModel {
return SocialLoginRequestModel(
token = entity.token,
provider = entity.provider
)
}
override fun map(entity: SocialLoginRequestEntity): SocialLoginRequestModel {
return SocialLoginRequestModel(
token = entity.token,
provider = entity.provider
)
}
}
I think the second implementation is the more clear as the map method is more readable.