Provide default implicit parameters in derives
when Case Class with type parameters
#17714
Replies: 3 comments
-
It's the same problem as the code in Scala2. case class Foo[T](model: Option[T], message: String)
object Foo {
implicit def model1Encoder(implicit enc: Encoder[T]): Encoder[Foo[T]] = derivesEncoder
} But not case class Foo[T](model: Option[T], message: String)
object Foo {
implicit def model1Encoder(implicit enc: Encoder[Option[T]]): Encoder[Foo[T]] = derivesEncoder
} In fact, if derives can provide implicit parameters, the derived method implemented can even no need to consider with type parameters. |
Beta Was this translation helpful? Give feedback.
-
And further, I think |
Beta Was this translation helpful? Give feedback.
-
Moreover, there are cases where that trait Shape[S] {
def inlets(shape: S): Set[Inlet[?]]
def outlets(shape: S): Set[Outlet[?]]
}
case class FlowShape[A, B](in: Inlet[A], out: Outlet[B]) derives Shape
// expected derivation:
given Shape[FlowShape] with {
def inlets(s: FlowShape): Set[Inlet[?]] = Set(s.in)
def outlets(s: FlowShape): Set[Outlet[?]] = Set(s.out)
}
Derivation mechanism should be more flexible in cases like this. |
Beta Was this translation helpful? Give feedback.
-
Now there is a product environment.
like I use play-json. Then I can
Then perhaps when in the code
summon[Foo[String]]
, I need to provide the Reads[Option[T]].In play-json, it needs to provide a special Reads for Option[String].
But now I write a common [T] =>> Reads[Option[T]] in my project and I don't want to import it in the target code when it finally need Reads[Option[T]]. I want to do something like.
But not
To be short, some transformation details of
given
should be manually enclosed when the case class is defined.Beta Was this translation helpful? Give feedback.
All reactions