There is a case class that looks like this:
case class User(
id: Long,
name: String,
email: String)
I want to use Scala macro to generate a function like below:
def makeUser(
id: Long = 1L,
name: String = "some name",
email: String = "some email"): User = {
User(
id = id,
name = name,
email = email)
}
It's verbose, and Scala macro can solve this verbosity (I hope). I don't care much about the default values; they can be random values.
I wonder if anyone can give me a code example. Thank you.
Edit: I'd like to clarify more about what I want. The function will only be used in unit tests, so I'd like to avoid littering my case classes with default values. (Thanks @Tyler for pointing it out).
Edit2: Also, I'd like to learn more about Scala's Macro. Therefore, if there's a macro example that achieves this, it would be a good lesson for me.