indigo icon indicating copy to clipboard operation
indigo copied to clipboard

Provide Circe codec instances of common Indigo types

Open davesmith00000 opened this issue 9 months ago • 1 comments

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 avatar May 09 '24 08:05 davesmith00000

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)

davesmith00000 avatar May 09 '24 08:05 davesmith00000