This one is out of curiosity, as I was trying something out…
Essentially I was looking for what one used to do with implicit def ..
in Scala 2.*, where the function took an implicit parameter. The goal being to lift an implicit of one type to being an implicit of another with a one-liner expression that formed the method body. For example, using Eq.by
with some mapping function to morph an Eq[X]
to some Eq[Wrapped[X]]
.
I’m aware that Scala 3 has given alias syntax, which seems to be the analogue of implicit val ....
.
Is there a generic variant of this?
I can write this out in longhand as a generic given ... with
, but would prefer to just have the equivalent of:
implicit def liftEqToWrapped[X]
(implicit val unlifted: Eq[X]): Eq[Wrapped[X]] =
Eq.by[Wrapped[X], X](_.extract)
(This may not compile as I’m thinking directly into the Internet, but you get the idea.)
The reason why I’m merely curious is that a) I can get away with freezing the type X
and thus can use a monomorphic given and b) I gather there is auto-typeclass derivation for Eq
.