Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide Circe codec instances of common Indigo types #736

Open
davesmith00000 opened this issue May 9, 2024 · 1 comment
Open

Provide Circe codec instances of common Indigo types #736

davesmith00000 opened this issue May 9, 2024 · 1 comment
Labels
enhancement New feature or request good first issue Good for newcomers help welcome Extra attention is needed

Comments

@davesmith00000
Copy link
Member

Perhaps they could be generated and live in the JSON module to keep all the circe stuff together? Be nice if you could do:

import indigo.circe.given (you have to import given's explicitly)

@davesmith00000 davesmith00000 added enhancement New feature or request good first issue Good for newcomers help welcome Extra attention is needed labels May 9, 2024
@davesmith00000
Copy link
Member Author

Reference from a recent project:

import indigo.*

import io.circe.*
import io.circe.syntax.*
import io.circe.generic.semiauto.*

object CirceIndigoInstances:

  given Decoder[Size] = deriveDecoder
  given Encoder[Size] = deriveEncoder

  given Decoder[Point] = deriveDecoder
  given Encoder[Point] = deriveEncoder

  given Decoder[Rectangle] = deriveDecoder
  given Encoder[Rectangle] = deriveEncoder

  given [A](using Decoder[A]): Decoder[Batch[A]] =
    Decoder.instance(_.as[List[A]].map(Batch.fromList))

  given [A](using Encoder[A]): Encoder[Batch[A]] =
    Encoder.instance(_.toList.asJson)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers help welcome Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant