Skip to content

Need help: implement wireImplicit. #273

Description

@djx314

https://scastie.scala-lang.org/djx314/6B1sptQ8QiywZcpciSlgHg/94

I have implemented a circe (En/De)coder in a simple way in this sample.

See some code

case class CirceModel(name: String, id: Long, age: Int, nick: String) // Model in when you are developing.
class TestModel[Ctx[_]] {
  case class CirceModel(name: Ctx[String], id: Ctx[Long], age: Ctx[Int], nick: Ctx[String])  // Model in this sample.
}

In this sample, CirceModel is TestModel[Id]#CirceModel, Encoder[CirceModel] is TestModel[Encoder]#CirceModel and Decoder[CirceModel] is TestModel[Decoder]#CirceModel.

And slick is just TestModel[Id]#CirceModel, TestModel[Rep]#CirceModel and TestModel[Shapel[FlatShapeLevel, Rep[*], _, _]]#CirceModel, and then just throw it to runtime and no need compile time any more.

So all is TestModel[Ctx[_]], but it's hard to translate it to

class TestModelDecoder(implicit name: Decoder[String], id: Decoder[Long], age: Decoder[Int], nick: Decoder[String]) extends TestModel[Decoder]#CirceModel(name = name, id = id, age = age, nick = nick)

and it's not the best practices.

I wonder if it can translate to something that in macwire like

val ctx = new TestModel[Decoder]
object TestModelDecoder {
  def input(name: Decoder[String] = implicitly, id: Decoder[Long] = implicitly, age: Decoder[Int] = implicitly, nick: Decoder[String] = implicitly): ctx.CirceModel = ctx.CirceModel(name = name, id = id, age = age, nick = nick)
}

so that I can

val ctx = wire[TestModel[Decoder]]
implicit val decoderImpl: Decoder[ctx.CirceModel] = translateDecoder(wireImplicit[ctx.CirceModel].input(age = CusDecoder.myIntDecoder.notToUseSnakeName.defaultValue(2), id = Decoder.from[Long].filter(i => i > 0)))

Injection, generic, refined, slick, the Meta of Model, and the Model itself, all is TestModel[Ctx[_]]#CirceModel.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions