47degrees / case-classy

configuration with less hassle
http://47deg.github.io/case-classy/
Apache License 2.0
68 stars 8 forks source link

Support for optional ADT #68

Open BenFradet opened 7 years ago

BenFradet commented 7 years ago

If we go back to the example in the readme, I'd like to be able to do:

import classy.generic._
import classy.config._

sealed trait Shape
case class Circle(radius: Double) extends Shape
case class Rectangle(length: Double, width: Double) extends Shape

case class MyConfig(
  someString: String,
  shape: Option[Shape])

import com.typesafe.config.Config
val decoder1 = deriveDecoder[Config, MyConfig]

decoder1.fromString("""someString = hello""")
BenFradet commented 7 years ago

Right now to make it work, I have to write:

decoder1.fromString("""someString = hello
  shape { none {} }""")
// res0: Either[classy.DecodeError,MyConfig] = Right(MyConfig(hello,None))

Seems like an issue with implicit ordering because Option is being treated as a coproduct, afaict.

andyscott commented 7 years ago

This seems like an oversight on my part. I can take a peek at a fix soon.

BenFradet commented 7 years ago

If you have pointers, I'd be happy to help 👍