In my codebase I used tags to encode some information into types. As tags works using t.asInstanceOf[T @@ U]
I could get away with many troubles with writing mapping between wrapped and unwrapped values.
Recently I hit the wall with tagged types as they break some functionality in shapeless that I would like to use, so I am trying to use value classes.
So far I could cheat away some e.g. boolean checks with tagged types using something like:
implicit class TaggedBooleanAsFirstOperand[P1, U](val c: Rep[P1 @@ U]) {
private val em = new BooleanColumnExtensionMethods[P1](c.asInstanceOf[Rep[P1]])
type o = OptionMapperDSL.arg[Boolean, P1]
def @&&[P2, R](b: Rep[P2])(implicit om: o#arg[Boolean, P2]#to[Boolean, R]): Rep[R] = em.&&[P2, R](b)
def @||[P2, R](b: Rep[P2])(implicit om: o#arg[Boolean, P2]#to[Boolean, R]): Rep[R] = em.||[P2, R](b)
def unary_! : Rep[P1] = em.unary_!
}
implicit class TaggedBooleanAsSecondOperand[P1](val c: Rep[P1]) {
private val em = new BooleanColumnExtensionMethods[P1](c)
type o = OptionMapperDSL.arg[Boolean, P1]
def &&@[P2, U, R](b: Rep[P2 @@ U])(implicit om: o#arg[Boolean, P2]#to[Boolean, R]): Rep[R] = em.&&[P2, R](b.asInstanceOf[Rep[P2]])
def ||@[P2, U, R](b: Rep[P2 @@ U])(implicit om: o#arg[Boolean, P2]#to[Boolean, R]): Rep[R] = em.||[P2, R](b.asInstanceOf[Rep[P2]])
}
implicit class TaggedBooleanAsBothOperands[P1, U](val c: Rep[P1 @@ U]) {
private val em = new BooleanColumnExtensionMethods[P1](c.asInstanceOf[Rep[P1]])
type o = OptionMapperDSL.arg[Boolean, P1]
def @&&@[P2, V, R](b: Rep[P2 @@ V])(implicit om: o#arg[Boolean, P2]#to[Boolean, R]): Rep[R] = em.&&[P2, R](b.asInstanceOf[Rep[P2]])
def @||@[P2, V, R](b: Rep[P2 @@ V])(implicit om: o#arg[Boolean, P2]#to[Boolean, R]): Rep[R] = em.||[P2, R](b.asInstanceOf[Rep[P2]])
}
With AnyVal
however, I cannot simply cast one type into the other where I want to, and I would have to provide some honest code allowing to achieve what I want.
I tried to read Slick source code, but the whole idea where should I start is a little blurry to me - relevant information are spread across many places, so I cannot simply pinpoint a few places to e.g. figure how to map one Rep
into the other or extract data from wrapped and unwrapped Boolean and combine them.
Can some Slick experts recommend some good starting point for those?