catapult icon indicating copy to clipboard operation
catapult copied to clipboard

Circe module for json variation

Open zarthross opened this issue 1 year ago • 4 comments

Would y'all be open to a circe module for json variation to make it easier to work with Json?

zarthross avatar Jul 25 '24 17:07 zarthross

@bplommer Thoughts?

zarthross avatar Aug 02 '24 17:08 zarthross

This is definitely something I think would be good to have. What sort of API do you envisage? I guess the core functionality would be a pair of methods for converting between Circe's Json and LD's LDValue (and that would be a good start for sure) but it feels a bit clumsy still - maybe a pair of extension methods like toCirce and toLDValue would make it nicer to work with, what do you think?

bplommer avatar Aug 11 '24 16:08 bplommer

I thinking along the lines of extension methods for LaunchDarklyClient[F]

implicit class LaunchDarklyClientExt[F[_]: Monad](private val client: LaunchDarklyClient[F]) {
    def circeValueVariation[Ctx: ContextEncoder, A: Encoder: Decoder](
      featureKey: String,
      context: Ctx,
      defaultValue: A,
  ): F[Decoder.Result[A]] = ???

or Just

implicit class LaunchDarklyClientExt[F[_]: MonadThrow](private val client: LaunchDarklyClient[F]) {
    def circeValueVariation[Ctx: ContextEncoder, A: Encoder: Decoder](
      featureKey: String,
      context: Ctx,
      defaultValue: A,
  ): F[A] = ??? // Lift the decoder failure into F

zarthross avatar Aug 15 '24 17:08 zarthross

I've given this a go #171 , though in a separate commit so it can be spun into a separate PR if desired.

morgen-peschke avatar Apr 01 '25 23:04 morgen-peschke