I have this type which will be generated via shapeless:
type hlistt = STUDENT.type :: AUTO_LOANS.type :: HNil
Basically I have a bunch of case objects extending a trait so I managed to create a method which gives me instances of all case objects as an HList
Then using import shapeless.ops.hlist.Last and init I wrote a method to retrieve one of the nodes in the HList if the value is equal to the string "student":
def getLast(hl:hlistt) = {
val last0=Last[hlistt]
val la=last0(hl)
if (la.value == "student") la
else init(hl)
}
The issue is that if I call this method I will not get the correct node type from the HList.
getLast(STUDENT :: AUTO_LOANS :: HNil)
The method works and returns the node but the type is off:
Product with Serializable = STUDENT :: HNil
Do I need some Witness/Aux implicits to return the correct type?
lais of typeAUTO_LOANS.type,init(hl)is of typeSTUDENT.type :: HNil, sois of type
Any(orProduct with Serializable).If you would like to return values of different types from different branches you need a
Poly.This approach works if the string is known at compile time.