toList for data classes

I’ve found a couple scenarios where it would be nice to unpack the components of a data class instance to a list.

Unfortunately, I don’t think there is any way to do this generically without language support, because:

  1. I don’t know of a way to add extension methods to data classes.
  2. Would have to use code generation or reflection to call all componentN() methods.

I wonder if others would find such a thing useful?

1 Like