Open davesmith00000 opened 6 months ago
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)
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)