Skip to content

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

@afsalthaj

Description

@afsalthaj

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions