When creating a class from another class which have the exact same field names as the parameters for...
f
When creating a class from another class which have the exact same field names as the parameters for the constructur, like this:
Copy code
fun fromData(data: Food) = DTOFood(
  id = data.id,
  whenCreated = data.whenCreated,
  whenModified = data.whenModified,
  singularName = data.singularName,
  pluralName = data.pluralName,
  singularNameIsStandard = data.singularNameIsStandard,
  searchTags = data.searchTags,
  category = data.category
)
Is there like a helper function available or how do you write a helper function like that to avoid having to do this?
m
You should be able to write something like this:
Copy code
fun Food.toDTO(): DTOFood {
  return DTOFood(id=this.id, ...)
}
a
I cannot really say without looking at the details but if they have the exact same parameters, may be you could just include the class in the other class instead of copying all the fields over.
a
You could use
DTOFood::class.constructors.first().callBy(map)