recursively walking a case class hierarchy

18 views
Skip to first unread message

Mark Kegel

unread,
Dec 10, 2015, 12:27:19 PM12/10/15
to Shapeless Dev
I am trying to walk a case class type hierarchy at runtime to find if certain fields exist or not -- basically I'm writing a simple query of fields in the type hierarchy. I would prefer not to use reflection given the runtime overhead, but I haven't been able to figure out how to get shapeless to do what I require.

At runtime I start with a dot-separate String query, say "maker.founded". Let's say this query is being executed over these case classes, with Wine as the root type:

case class Maker(address:String, founded:Int)
case class Wine(name:String, maker:Maker)

So the query "maker.founded" should find a field "maker" of type Maker in the Wine class and then a field "founded" of type Int in the Maker class.

I've been able to get the first level of key names by following the pattern here: http://stackoverflow.com/questions/27434302/extract-label-values-from-a-labelledgeneric-instance

However, its not clear to me how I recurse into the next level so that I can enumerate the keys of the queried field dynamically.

Miles Sabin

unread,
Dec 10, 2015, 2:05:37 PM12/10/15
to shapel...@googlegroups.com
Hi Mark,

This mailing list has been more or less deprecated in favour of the
shapeless gitter channel ... you'll find lots of people there who'll
be able to point you in the right direction,

https://gitter.im/milessabin/shapeless

Cheers,


Miles
> --
> You received this message because you are subscribed to the Google Groups
> "Shapeless Dev" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to shapeless-de...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



--
Miles Sabin
tel: +44 7813 944 528
skype: milessabin
gtalk: mi...@milessabin.com
http://milessabin.com/blog
http://twitter.com/milessabin

Mark Kegel

unread,
Dec 10, 2015, 2:21:36 PM12/10/15
to Shapeless Dev
Oh thank you! I'll my question there. 
Reply all
Reply to author
Forward
0 new messages