ccadllc/cedi-config

Is there a better way to derive ConfigParser without leaking DerivedConfigFieldParser?

afsalthaj opened this issue · 0 comments

I have an ADT as given below:


abstract sealed class Location(val name: String)

object Location {
  final case object AustraliaEast extends Location("australiaeast")

  def fromString(name: String): Location = name match {
    case AustraliaEast.name => AustraliaEast
  }
}

I derive the ConfigParser for Location by specifying the DerivedConfigFieldParser for location.

 implicit val locDerivedConfigFieldParser: DerivedConfigFieldParser[Location] =
      implicitly[DerivedConfigFieldParser[String]].map(Location.fromString)

Is there already a better way of doing it?

If not, it would be more intuitive to define just a ConfigParser[Location] (using the ConfigParser[String]). Something along the below lines.

implicit val configParser: ConfigParser[Location] = 
  ConfigParser[String].map(Location.fromString)

Looking at the code, it feels we could bring this behavior.