2

I have a structure that looks like so:

case class BfxCandle(mts: Long, open: Float, close: Float, high: Float, low: Float, volume: Float)

It's JSON encoding is the following:

[1000, 10, 10, 10, 10, 100]

And it's companion class features a decoder:

object BfxCandle {
  type tuple = (Long, Float, Float, Float, Float, Float)

  implicit val decoder: Decoder[BfxCandle] = (c: HCursor) =>
    for (elements <- c.as[tuple])
      yield (BfxCandle.apply _).tupled(elements)
}

This works great but as a Scala student I'm looking for more. Is there a way to derive the tupled type from the case class?

Ploo
  • 417
  • 1
  • 5
  • 12

0 Answers0