Skip to content

Provide default implicit parameters in derives when Case Class with type parameters #17713

@djx314

Description

@djx314

Now there is a product environment.

case class Foo[T](model: Option[T], message: String)

like I use play-json. Then I can

case class Foo[T](model: Option[T], message: String) derives Reads

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.

import special.given
case class Foo[T](model: Option[T], message: String) derives(using Reads[T]) Reads
// target code
Json.toJson(Foo(Option(21), 3))

But not

case class Foo[T](model: Option[T], message: String) derives Reads
// target code
import special.given
Json.toJson(Foo(Option(21), 3))

To be short, some transformation details of given should be manually enclosed when the case class is defined.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions