Is it possible to map through a data class?
# announcements
r
Is it possible to map through a data class?
m
rohith: what do you mean?
r
if I have a data class e.g:
data class Foo(val bar: String, val fizz: String, val buzz: String)
and I create an instance of said class,
val fooData = Foo("f", "i", "z", "z")
Is there a way for me to map across all the values
Copy code
fooData.map {

}
@menegatti
k
You'd probably have to use reflection for that.
m
was going to say the same thing
r
Damn okay
k
Or you can store those properties in a
Map<String, String>
and then you can delegate them to that map.
r
each data class has auto-generated methods called
componen1()
,
component2()
,... maybe this will be of some use to you
k
There's an example in the official docs about delegating to a map.
r
@karelpeeters got a link?
Thanks for all the help btw 🙂