Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
afsalthaj opened this issue Jul 24, 2018 · 0 comments

Comments

@afsalthaj
Copy link

afsalthaj commented Jul 24, 2018

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant