Yes, this is a pretty thick thing.
The smart bend here is that hconsSize is recursive, not actually self-relational.
Both apply and hconsSize extend the implicit type Size[X] . There are only two implications that can match this score:
hnilSize , but only if X is an HNil typehconsSize
So, apply inserts an hconsSize implicit, which adds 1 to the stack and pulls an implicit hconsSize into another (not necessarily in that order). This continues until we encounter an element of type HNil . Then the implicit hnilSize is pulled in, get is zero, the stack is expanded, and all these 1 add up.
Result: number of elements in a shapeless HList.
source share